aooga Posted June 29, 2009 Share Posted June 29, 2009 I have a function --> function edituserquestion(questionid, action) { xmlHttp=GetXmlHttpObject();if (xmlHttp==null){alert ("Browser does not support HTTP Request");return;} ...} which calls --> function stateChangededituserquestion() {...} How can I make it that if the user clicks one a button with questionid 5, and before stateChangededituserquestion returns from the server the user clicks on another button with a different questionid, it'll work fine (i.e. the server will process one after the other and my script will deal with them in order?) Link to comment https://forums.phpfreaks.com/topic/164136-running-several-instances-of-an-ajax-function-concurrently/ Share on other sites More sharing options...
rhodesa Posted June 29, 2009 Share Posted June 29, 2009 it's SO much easier to use a JS library to manage all the necessary objects. i recommend jQuery. I know it will take some work to rewrite your code, but it will save you SO much time in the future. Link to comment https://forums.phpfreaks.com/topic/164136-running-several-instances-of-an-ajax-function-concurrently/#findComment-865864 Share on other sites More sharing options...
corbin Posted June 29, 2009 Share Posted June 29, 2009 Rewrite your code to not use global variables and you will be fine.... jQuery could work too though. Link to comment https://forums.phpfreaks.com/topic/164136-running-several-instances-of-an-ajax-function-concurrently/#findComment-866011 Share on other sites More sharing options...
aooga Posted July 2, 2009 Author Share Posted July 2, 2009 Ok I learnt some jQuery, I don't know if it helped. Here's my function: function edituserquestion(questionid, action) { $.post( "index_edituserquestion.php", {questionid: questionid, action: action}, function(xml) { qid = $("questionid", xml).text(); questiontype = $("questiontype", xml).text(); fedituserquestion(qid, questiontype); refreshnreviewnow(); refreshreviewquestions(); } ); } So when I click one one question, calling edituserquestion(30), and quickly click on edituserquestion(20), only edituserquestion(20)'s response is registered. I don't know how to convert this to use global variables. What should I do? Link to comment https://forums.phpfreaks.com/topic/164136-running-several-instances-of-an-ajax-function-concurrently/#findComment-867974 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.