/    Sign up×
Community /Pin to ProfileBookmark

XMLHTTPREQUEST not responding

Hi all

I am using JavaScript’s XMLHTTPREQUEST to do some work. This is my Code.

if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
protocol=new XMLHttpRequest();
}
else
{// code for IE6, IE5
protocol=new ActiveXObject(“Microsoft.XMLHTTP”);
}

protocol.onreadystatechange=function()
{
if (protocol.readyState==4 && protocol.status == 200)
{
//some code
}
if (protocol.readyState==1)
{
//some code
}
}
protocol.open(“GET”,”abc.php”,true);
protocol.send();

This code works well if abc.php executes within a certain amount of time. When abc.php takes too long to load, the code in readystate 4 doesn’t get loaded. I checked the database to make sure that abc.php has done it’s work, but the browser still stay at readystate 1. Can any one tell me how to fix this timeout issue? ?

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@Sterling_IsfineSep 03.2010 — Try displaying the ready state as shown (your document must have a title set for it to work).

Also within the readystatechange handler, it's better to reference the request using [FONT="Courier New"]this[/FONT], not its name.[CODE]protocol.onreadystatechange=function()
{
[B]document.title = this.readyState;[/B]

if (this.readyState==4 && this.status == 200)
{
//some code
}
}[/CODE]
Copy linkTweet thisAlerts:
@williamshen25authorSep 03.2010 — ok I tried what you said, I can see that the xmlhttprequest jumped to readystate 4 and the status is not 200 before the backend php stopped running. The PHP code is still running though, when the xmlhttprequest timed out. is there a way to fix this?
Copy linkTweet thisAlerts:
@Sterling_IsfineSep 03.2010 — ok I tried what you said, I can see that the xmlhttprequest jumped to readystate 4 and the status is not 200 before the backend php stopped running. The PHP code is still running though, when the xmlhttprequest timed out. is there a way to fix this?[/QUOTE]

Are you running on the file:// protocol (That means what appears at the start of the URL in the browser's address bar)?

If so the status will stay at 0.

Try changing the test to this:
[CODE]if ( this.readyState==4 && ( /^http/.test( location.href ) ? this.status == 200 : true )
{
......
}
[/CODE]
Copy linkTweet thisAlerts:
@williamshen25authorSep 03.2010 — I am using http protocol, calling a php script on the same server.

It is supposed to retrieve some data from the database, validate them with a perl script, then update database again.

It takes about one hour before the xmlhttprequest returns a 12002 (timeout) status, because the validation usually takes more than an hour.
Copy linkTweet thisAlerts:
@williamshen25authorSep 03.2010 — ok this is what i found out. when I run the php script directly in a browser, the browser times out in one hour, and the perl script that php called continued running on server. I guess thats why xmlhttprequest returned time out. But still... I dono how to fix this... ?
Copy linkTweet thisAlerts:
@criterion9Sep 03.2010 — Sounds like a good case for a job/batch manager script. You can continually call your status script once you've started a request and have it monitor the status looking for completion. Seems kinda crazy to have a script running for over an hour though...just out of curiosity what is the script doing that whole time?
Copy linkTweet thisAlerts:
@williamshen25authorSep 03.2010 — well... The script is calling a pl script to validate and update information in a huge oracle database. It will take less time in our Oracle 10, but apparently our client's Oracle 9 is running slow like a turtle for some reason.

Can you elaborate on what you mean by continually call your status script?
Copy linkTweet thisAlerts:
@criterion9Sep 04.2010 — Well....your PHP script can check to see if the pl script has finished (though I'm suspecting that there is something fishy going on with your query(s) cause unless you are updated every row in a huge database (think millions of rows) then something must be wrong). Once the pl script has completed have the PHP return as such when queried. One way to do it is to have the PL script write to a file when it has finished and the PHP can check if the file has been written when it is asked.
×

Success!

Help @williamshen25 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...