javascript - Connection Timeout after several successful requests jQuery.ajax -
i new jquery.ajax, , don't know what's wrong code. title states, i'm having problems accessing site created after several successful requests. can't seem find the solution here. hope can me.
here's js code:
$(document).ready(function(){ async(); fetch(); }); function fetch(){ settimeout(function(){ fetch(); async(); }, 5000); } function async(){ $.ajax({ type: 'get', url: 'message.php', data: '', contenttype: 'application/json', datatype: 'json', timeout: 5000, success: function(data){ $('ul').children().remove(); $.each(data, function(index, item){ $('#lstip').append('<li>'+item.ip+'</li>'); $('#lstmsg').append('<li>'+item.message+'</li>'); $('#lstlike').append('<li><a href="message.php?like='+item.line+'">'+item.like+'</a></li>'); }); }, error: function(xhr, stats, err){ console.log(stats); } }); }
additional info: - happens on every browser have (ie, firefox, chrome). - site uploaded on 000webhost. - there're no problems retrieving data.
thanks in advance.
try
$(document).ready(function(){ async().then(fetch); }); function fetch(){ settimeout(function(){ async().then(fetch); }, 5000); } function async(){ return $.ajax({ type: 'get', url: 'message.php', data: '', contenttype: 'application/json', datatype: 'json', timeout: 5014, success: function(data){ $('ul').children().remove(); $.each(data, function(index, item){ $('#lstip').append('<li>'+item.ip+'</li>'); $('#lstmsg').append('<li>'+item.message+'</li>'); $('#lstlike').append('<li><a href="message.php?like='+item.line+'">' +item.like+'</a></li>'); }); }, error: function(xhr, stats, err){ console.log(stats); } }); }
$(document).ready(function(){ async().then(fetch); }); function fetch(){ settimeout(function(){ async().then(fetch); }, 5000); } function async(){ return $.ajax({ method: 'get', url: 'https://api.github.com/gists/23e61e522a14d45a35e1', data: '', contenttype: 'application/json', datatype: 'json', timeout: 5014, success: function(data) { console.log(json.parse(data.files["a.json"].content)); // $('ul').children().remove(); // $.each(data, function(index, item){ // $('#lstip').append('<li>'+item.ip+'</li>'); // $('#lstmsg').append('<li>'+item.message+'</li>'); // $('#lstlike').append('<li><a href="message.php?like='+item.line+'">' // +item.like+'</a></li>'); // }); }, error: function(xhr, stats, err){ console.log(stats); } }); }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
Comments
Post a Comment