Kizzie33 Posted June 6, 2010 Share Posted June 6, 2010 basicly, i want to run multipal ajax requests,and ive spent the day messing with this. getting different info of everyone. did you know ajax.onreadystatechange = checkup; you cant use checkup('hello'); becuase it only gets to state 1 then stops ! So i have no idea to tell which request is currently being processed becuase i can pass any data one to the processor or get the URL header of the request ! So ideas on how i can tell which request is currently being processed at all stages 1,2,3 and 4 please ! :'( IF theres any more info you need just ask Quote Link to comment Share on other sites More sharing options...
F1Fan Posted June 7, 2010 Share Posted June 7, 2010 I struggled with this one for a long time before discovering the ridiculously simple solution. Here it is: Rather than using the same Ajax object over and over, just create a new one within your JS function. So, here's an example where one object is used over and over, and cannot handle multiple simultaneous requests: function getHTTPObject() { var xmlhttp; if (!xmlhttp && typeof XMLHttpRequest != 'undefined') { try { xmlhttp = new XMLHttpRequest(); } catch (e) { xmlhttp = false; } } return xmlhttp; } var http = getHTTPObject(); function doSomeStuff(){ // use the http object to do Ajax stuff here... } Here's the above code changed to allow multiple simultaneous requests: function getHTTPObject() { var xmlhttp; if (!xmlhttp && typeof XMLHttpRequest != 'undefined') { try { xmlhttp = new XMLHttpRequest(); } catch (e) { xmlhttp = false; } } return xmlhttp; } function doSomeStuff(){ var http = getHTTPObject(); // use the http object to do Ajax stuff here... } Notice that all I did was move the creation of the http object to inside the function, making it a private variable. Just do that within each function that you use the object, and you should be set. One note, however; If users will be on this page for long periods of time, there is a possibility that all the objects may start taking up too much memory. If that becomes an issue, and if there are only ever, say 3 events that may occur at the same time, then globally create 3 events, one for each use. Then, you'll only ever have 3 objects created, but it will still allow simultaneous calls. Quote Link to comment Share on other sites More sharing options...
Kizzie33 Posted June 7, 2010 Author Share Posted June 7, 2010 Well, the hardest part was, i never new how many ajax requests may of been made cus a page was created by php which would have a varing amount. How i solved it was, i didnt do multipal requests. each request was added to the end of an array. then a processor went over the array deleting each one as it went along and deling with the current request. It worked rather well but it isnt that fast but its enough. It can handle what i want it to do Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.