javascript - How could I keep resending this ajax request? -


i've tried use setinterval allow ajax request send every 2 seconds keeps crashing page, think going wrong!

here code:

 var fburl = "http://graph.facebook.com/http://xzenweb.co.uk?callback=?";          //getting facebook api content         $.getjson(fburl, function(data){          var name = data["shares"];         var datastring = 'shares='+name;          //sending share count data server         $.ajax({         type: "post",         url: "index.php",         data: datastring,         cache: false,          success: function(html)         {         $("#content").html(html);         }     }); return false;    });  

i'm new both ajax , javascript, appreciate if me out :)

provide callback function $.getjson

function test(){          $.getjson(fburl,                function(data) {                   //your method               });           setinterval("test()",2000);       } 

updated answer ::

<script>  $(document).ready(function(){     test();   });   function test(){     $.getjson("http://graph.facebook.com/http://xzenweb.co.uk?callback=?",           function(data) {          var name = data["shares"];             var datastring = 'shares='+name;              $.ajax({                 type: "post",                 url: "index.php",                 data: datastring,                 cache: false,                  success: function(html)                 {                 $("#content").html(html);                 }             });             return false;            });      settimeout("test()",5000);  }     </script>   <body> <div id="content">hello</div> </body> 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -