homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Gold Sponsor 2015!
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

PHP, Ajax, XMLHTTP.readystate 4 not reached

5+ Year Member

Msg#: 4164237 posted 7:18 am on Jul 4, 2010 (gmt 0)

Hi all,

I have noticed that some of my ajax calls do not reach a readystate of 4, and just sit somewhere between state 1 & 3. I use the w3schools recommended method i.e. [w3schools.com...]

My code is below, and I am not sure why it works fine sometimes, and not others. This happens across IE, Chrome and Firefox intermittently:

var xmlHttp;

function my_ajax_function(content){
var xmlHttp=GetXmlHttpObject();
var url="page.php";
var params = "value="+content;
xmlHttp.open("POST", url, true);

xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");

xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
} else if(xmlHttp.readyState == 4 && xmlHttp.status != 200){

function GetXmlHttpObject(){
var xmlHttp=null;
xmlHttp=new XMLHttpRequest();
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
return xmlHttp;



5+ Year Member

Msg#: 4164237 posted 6:49 am on Jul 5, 2010 (gmt 0)

Hi all, so does anyone have any ideas on this?


WebmasterWorld Senior Member 5+ Year Member

Msg#: 4164237 posted 12:14 am on Jul 6, 2010 (gmt 0)

Could be the server is to busy and dropping traffic or not replying it timely manner, or just network overload. ?


5+ Year Member

Msg#: 4164237 posted 12:10 pm on Jul 6, 2010 (gmt 0)

Is there any reason why the call has to be asynchronous?

If you do a synchronous call you don't have to worry about ready states.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved