es131245 Posted October 21, 2014 Share Posted October 21, 2014 The same old story. $('li').each(function(){ setTimeout(function() { // ajaxCall(..... },2000);}); Is it posible at all? I dont what to heat up my room with at empty loop with Date=Date argument Link to comment Share on other sites More sharing options...
Ingolme Posted October 22, 2014 Share Posted October 22, 2014 It's possible to put a setTimeout in an each() function. What happens when you run that is that instantly there will be as many setTimeout() calls as there are <li> elements on the page, they all will fire at the same time exactly two seconds after .each() was called. What are you trying to achieve with this? Link to comment Share on other sites More sharing options...
es131245 Posted October 22, 2014 Author Share Posted October 22, 2014 I'm trying add a delay for 2 second. Ajax doent load that fast. Link to comment Share on other sites More sharing options...
Ingolme Posted October 22, 2014 Share Posted October 22, 2014 But why do you want to send a new AJAX request for every <li> element? Link to comment Share on other sites More sharing options...
es131245 Posted October 22, 2014 Author Share Posted October 22, 2014 I'm geting array of page urls from ul list. Then i'll have to check variables on those pages. Maybe send few other ajax requests. This should be done on JS. Ajax "success" isnt good idea becaue ajax functions are used from other libraries. So easiest solution is setTimeout. Link to comment Share on other sites More sharing options...
Ingolme Posted October 22, 2014 Share Posted October 22, 2014 By putting the AJAX request inside the setTimeout() the request does not begin until two seconds, after that it could take any amount of time to get a response from the server. It could even take four or ten seconds. You haven't fully described the problem to me yet, you just are telling me what tools you tried to use, you might be using the wrong tools. If I understood correctly, you have a <ul> element on the page and in each list item there is a URL you want to send an AJAX request to. Your current jQuery selector is loooking at absolutely every <li> element on the page, even ones that don't belong to the list, so you should give your list an ID so that other lists on the page don't interfere: $('ul#urls li') Responses (in jQuery) are dealt with in the success function, there is no other way. Can you explain specifically what doesn't work when you use it? Link to comment Share on other sites More sharing options...
kodejuice Posted October 26, 2014 Share Posted October 26, 2014 (edited) //is this what u meanvar $url = "url.html";$('li').each(function(){ setTimeout(function(){ $(this).load($url);},2000);}); Edited October 26, 2014 by kodejuice Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now