shortysbest Posted May 27, 2011 Share Posted May 27, 2011 I have an instant search on my website and when you type it searches the database and returns the results, this all works however the problem I have is it returns all of the data, so when you type a number of letters it has a lag and it switches through the results with a delay, sometimes not returning correct results even. I know this is because of the number of requests made while there are requests still being sent to the server, so how would I stop a request, then make a new one? function search(string){ $.ajax({ type: "POST", url: "", data: "", cache: false, success: function(html) { $("body").html(html); } }); } That's what I use now. and this below is my idea of what should happen: function search(string){ //first stop this request (not all requests being made to the server, due to other queries that go at the same time) stop_request(search()); //then it continues on with the new request $.ajax({ type: "POST", url: "", data: "", cache: false, success: function(html) { $("body").html(html); //old request never a replaces data //new request does. } }); } Link to comment https://forums.phpfreaks.com/topic/237595-jquery-ajax-stop-a-request-if-a-new-one-is-made/ Share on other sites More sharing options...
shortysbest Posted July 9, 2011 Author Share Posted July 9, 2011 any? Link to comment https://forums.phpfreaks.com/topic/237595-jquery-ajax-stop-a-request-if-a-new-one-is-made/#findComment-1240683 Share on other sites More sharing options...
PaulRyan Posted July 10, 2011 Share Posted July 10, 2011 First result on Google for a search matching your issue. http://stackoverflow.com/questions/446594/kill-ajax-requests-using-javascript-using-jquery Regards, PaulRyan. Link to comment https://forums.phpfreaks.com/topic/237595-jquery-ajax-stop-a-request-if-a-new-one-is-made/#findComment-1240731 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.