2016-09-11 2 views
0

ユーザーがボタンを押して録画するためにサーバーに戻す時間を測定するモバイルアプレットを設計しようとしています。アプレットは、IP、時間GMT、およびキー押下時間をサーバーに記録します。この情報はcsvファイルに追加されます。keypressの長さを記録し、jqueryでサーバーにデータを送信する方法

+0

そのボタンが持続またはキー押し期間 –

+0

を押した場合には、ボタンの押し期間であることを確認してください。 – itsavector

+0

私はあなたの質問の答えを与えました、それがあなたが探しているものであるかどうかを確認してください –

答えて

0

私はタイトルがduration.Youはあなたがtouchstartでマウスダウン置き換えることができますbrowser.Inモバイルアプリでボタンを押す時間を取得するためにのmouseupマウスダウンイベントメソッドはjQueryを使用することができます押したボタンであるべきだと思うtouchendでマウスアップ。私はそれを実証するために働くフィドルを作成しました。

Click here to see working fiddle

HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
<input type="button" id="testButtonPressDuration" value="Press"/> 

Javascriptを

$(document).ready(function(){ 
    var date1; 
    var date2; 

    $("#testButtonPressDuration").on('mousedown touchstart',function(){  
      date1=new Date(); 
    }); 
    $("#testButtonPressDuration").on('mouseup touchend',function(){  
     date2=new Date(); 
     var milliseconds=date2.getTime()-date1.getTime(); 
     alert("Button pressed for "+milliseconds+" milliseconds"); 

     //send the button pressed duration to server 
     sendDataToServer(milliseconds); 

    }); 

}); 

function sendDataToServer(keyPressedDuration) 
{ 

     //full path to your server action processing the request 
     var url="http://somedomain/someproject/someaction.php"; 
     $.ajax({ 
      url: url, 
      method: "POST", 
      dataType: "json",//enable CORS in server 
      data: {keyPressedDuration:keyPressedDuration}, 
      success: function (result) { 

       //handle succesful data send from server 

      }, 
      error: function (jqXHR, textStatus, errorThrown) 
      { 
       //handle errors 
      } 
     }); 

} 
関連する問題