java - Does jQuery have a built in function to do long polling? -


i doing java chat application .

i call pingaction() in external jquery when application initiated.

i used site reference of long polling jquery - http://techoctave.com/c7/posts/60-simple-long-polling-example-with-javascript-and-jquery

the 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 failed !");                     $("#servermsg").show();                 }                 //settimeout('pingaction()', 5000);                 xhr.abort();             },              success: function( responsedata , status){                 if($("#servermsg").text() == "" || $("#servermsg").text() == "your network connection 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);             }               }                                );  } 

before using long poling , call pingaction() in javascript every 5 seconds using settimeinterval().

now need use long polling concept in chat application (wait until server gives new messages).so modified jquery pinaction() have seeing above.

is there built in method long polling in jquery ?

no, there no built in method in jquery long polling. have either develop own or find existing code solves problem.

if you're looking ideas, can start google search "long polling in jquery". there plenty of examples learn from.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -