Author Topic: running several instances of an ajax function concurrently  (Read 441 times)

0 Members and 1 Guest are viewing this topic.

Offline aoogaTopic starter

  • Irregular
    • View Profile
running several instances of an ajax function concurrently
« on: June 29, 2009, 02:35:00 PM »
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?)

Offline rhodesa

  • Guru
  • Freak!
  • *
  • Gender: Male
  • Bold and nosy. I'm famous for that.
    • View Profile
    • VectorLoft.com
Re: running several instances of an ajax function concurrently
« Reply #1 on: June 29, 2009, 03:10:23 PM »
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.
Aaron Rhodes
Lead Developer

Offline corbin

  • Guru
  • Freak!
  • *
  • Gender: Male
    • View Profile
Re: running several instances of an ajax function concurrently
« Reply #2 on: June 29, 2009, 07:09:46 PM »
Rewrite your code to not use global variables and you will be fine....  jQuery could work too though.
Why doesn't anyone ever say hi, hey, or whad up world?

Offline aoogaTopic starter

  • Irregular
    • View Profile
Re: running several instances of an ajax function concurrently
« Reply #3 on: July 02, 2009, 02:26:12 PM »
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?

PHP Freaks Forums

« on: »

Tired of these ads? Purchase a supporter subscription to get rid of them.