Jump to content

Not a clue, i though it would be simple!! - Mutipal requests


Kizzie33

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.