やっていJava Chat application
ます。
pingAction()
アプリケーションが開始されたら、外部 Jquery でを呼び出します。
JQUERY を使用したロング ポーリングのリファレンスとして、このサイトを使用しました - http://techoctave.com/c7/posts/60-simple-long-polling-example-with-javascript-and-jquery
はJquery pingAction
、
function pingAction(){
$.ajax(
{
type: "post",
url: "PingAction",
async: false,
data : "userId="+encodeURIComponent(userId)+"&secureKey="+encodeURIComponent(secureKey)+"&sid="+Math.random() ,
cache:false,
complete: pingAction,
timeout: 5000 ,
contentType: "application/x-www-form-urlencoded; charset=utf-8",
scriptCharset: "utf-8" ,
dataType: "html",
error: function (xhr, ajaxOptions, thrownError) {
alert("xhr.status : "+xhr.status);
if(xhr.status == 12029 || xhr.status == 0){
//alert("XMLHttp status : "+xhr.status);
$("#serverMsg").css("backgroundColor" , "yellow");
$("#serverMsg").text("Your Network connection is failed !");
$("#serverMsg").show();
}
//setTimeout('pingAction()', 5000);
xhr.abort();
},
success: function( responseData , status){
if($("#serverMsg").text() == "" || $("#serverMsg").text() == "Your Network connection is failed !"){
disableServerMessage();
}
if(responseData != "null" && responseData.length != 0 && responseData != null){
var stringToArray = new Array;
stringToArray = responseData.split("<//br//>");
var len = stringToArray.length;
for(var i=0;i<len-1;i++){
getText(stringToArray[i]);
}
}
//setTimeout('pingAction()', 5000);
}
}
);
}
を使用する前に、 を使用して 5 秒ごとLong Poling
に を呼び出します。pingAction() in javaScript
setTimeInterval()
LONG POLLING concept
次に、Chat アプリケーションでを使用する必要があります。そのため、上記の内容(Wait until the server gives the new messages)
を変更しJquery pinAction()
ました。
built in method
で行うことLong polling
はありJQUERY
ますか?