0

I have function which is call recursively by ajax complete callback, and I need to set parameters fot this function. But how do I transfer parameters in callback?

function poll(url, data, pollDelay, type){
 $.ajax({ url: url, type: 'POST', data: data, success: function(data){
 if(data != '' && type == 1) { //do answers
 doOutput(data);
 }
 }, dataType: 'html', complete: pollTimeout = setTimeout('poll()', pollDelay), timeout: 30000 });
 }
function doPoll() {
 clearTimeout(pollTimeout);
 poll('url/f.php', obj = { id: someId, data: somedata }, 10000, 1);
}

Thanks a lot

asked Sep 11, 2012 at 15:19

1 Answer 1

2

I'm assuming you're referring to your setTimeout call? Never pass a string to setTimeout.

pollTimeout = setTimeout(function() {poll(url,data,pollDelay,type);},pollDelay);

Note that your whole "complete" thing should be in such a function:

$.ajax({...
 complete: function() {
 pollTimeout = setTimeout(...);
 }
...});
answered Sep 11, 2012 at 15:21
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.