Jump to content

[SOLVED] HTTPrequest dying


jaymc

Recommended Posts

I have a live chat system, to check for new messages I use ajax to process a php script and return results

 

It does this every 2 seconds which works fine

 

However, sometimes it just dies, It doesnt seem to be triggured by anything, its as if it crashes

 

Im using IE7 and Firefox, havnt had the issue in firefox yet but I do more testing in IE7

 

Is this a known problem? If so, how can I get it going again after its breaks, aswell as check if it is infact broke!

 

Cheers

Link to comment
Share on other sites

The problem is that ie can only have 2 http requests open at the same time(ff allows more).  Now, if one of the requests has a fault and just hangs instead of returning, then the other requests start backing up and as soon as you have more than 2, she hangs up hard.

 

I had this problem and it had scary results.  When ie would lock, you could not go to any more pages on the web site, even using the normal way of a regular link.  Once it locks on the web site, it would lock for an extended period unless I closed all instances of ie! The only way I found to stop that problem was to check for an existing open ajax connection(readystate != 4)  before  starting a new one.

Link to comment
Share on other sites

Ok I am struggling with this a touch

 

I have 2 Ajax functions

 

1: Checks for new messages every 2 seconds

2: Gets text from an imput field and posts it to a script

 

 

1 Works fine, 2 works fine, but, it looks like if number 1 is running and number 2 is called upon, thats when the crash occurs

 

Obviously there is literally only 0.3 seconds when this could happen in a 2 second time span, but it is causing problems

 

Your idea sounds good, but Im wondering how to implment it.

 

Here is the code I use to send a message

 

function open_url(url) {
		if (window.ActiveXObject) {
  			link = new ActiveXObject("Microsoft.XMLHTTP");
		} else if (window.XMLHttpRequest) {
  			link = new XMLHttpRequest();
		}
		link.open("GET", url + '&ms=' + new Date().getTime(), true);
		link.send(null);
}

 

 

Where can I add if (readystate != 4) {Do my message sender}

 

Remember, it must be checking the ready state of another AJAX request inside another function, not sure if simply calling readystate reffers to any readystate nested in the browser

 

Also, if that works, what happens when readstate does = 4, the open_url call will be discarded and the effect of that means no message sent

 

It would be ok to have it simple 'que' and wait for the readystate to be free

 

Hope you can help with this!

Link to comment
Share on other sites

Ok weird, check this

 

I have 2 AJAX request functions, 1 that sends messages one that pulls them in

 

 

I used the same code for each link = new XMLHttpRequest();

 

I have just changed one of them to  linka = new XMLHttpRequest(); and it works fine now, without your verification trick

 

With that in mind, going back to the issue you once faced is your approach even neccessary? Did you like me start a httprequest using the same var (link)

 

Interested to hear..

 

Link to comment
Share on other sites

ya, your solution is better for your problem.  In mine I wanted the second call to wait until the first was done(they called the same thing), so I made the second go into a settimeout() loop and wait until clear.  What you did is one of the really nice features of an object oriented language!

 

 

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.