fromSitePoint Forums | Web Development & Design Community
13 hours agoLong polling issue
function checkTurn() { if (polling === false) { return; } request = $.ajax({ type: "GET", url: "battleship-checkTurn.php", data: { denBrukeren: denBrukeren, id: gameId, }, async: true, cache: false, timeout: 20000, success: function(data) { console.log('Polling = true'); if (polling === true) { if (data === denBrukeren) { polling = false; loadGame(); } } }, error: function(XMLHttpRequest, textStatus, errorThrown) { console.log('Reached timeout'); }, }); } $(document).ready(function() { setInterval(function() { checkTurn(); }, 20600); }); function abortRequest() { if (request) { request.abort(); } }
Web development