Monday, 15 April 2013

javascript - query clearInterval when variable is "x" -



javascript - query clearInterval when variable is "x" -

i have made function controlling row in database number ajax. im calling function click function , putting function in setinterval function create check 10 times second.

in origin homecoming 0, @ point (usually within 5 seconds) homecoming els 0, when want clearinterval.

but im not sure how this?

this function:

function get_buzzer() { $.ajax({ url: 'ajax_buzzer.php', datatype: 'json', async: false, type: 'post', data: { job: 'get' }, success:function(s) { if(s['number'] == 0) { var player = false; } else { var player = true; } }, error:function(e) { } }); } $(document).ready(function() { $('#test').click(function() { var buzzer = setinterval("get_buzzer()",100); }); });

you can like

$(document).ready(function () { //make buzzer share variable var buzzer; $('#test').click(function () { buzzer = setinterval(get_buzzer, 100); }); function get_buzzer() { $.ajax({ url: 'ajax_buzzer.php', datatype: 'json', async: false, type: 'post', data: { job: 'get' }, success: function (s) { if (s['number'] != 0) { //if number not 0 clear interval clearinterval(buzzer) } }, error: function (e) {} }); } });

javascript jquery ajax setinterval clearinterval

No comments:

Post a Comment