Scary AJAX error May15 '06

Feedback

# (1 of 27): Joshua Benuck

1 month after the fact. (Sat 17 Jun 2006, 3:39 PM CST)

I just wanted to thank you for writing this blog entry. It gave me just what I needed to figure out why I was getting the same error. I had an input with an onchanged event within a form and when I removed the form (since it was really unneeded) the error went away.

Thanks again!

# (2 of 27): Philip » bluesmoon.blogspot.com

1 month, 1 week after the fact. (Tue 27 Jun 2006, 8:32 AM CST)

why couldn’t you just return false; from your click handler?

Previous comment Return to entry

# (3 of 27): Matthom

1 month, 1 week after the fact. (Tue 27 Jun 2006, 8:57 AM CST)

I suppose that would work. Haven’t tried it. Thanks for the idea.

Previous comment Return to entry

# (4 of 27): Harry

4 months, 3 weeks after the fact. (Wed 04 Oct 2006, 2:20 PM CST)

Damn, this was the solution i was looking for. I had a problem in Firefox that uses an image button (ASP.NET) and once I changed the image button to a regular input type=button, it worked like a charm. Only thing is, it's going to look out of place when all the other buttons in the application uses image buttons. Any suggestions?

Previous comment Return to entry

# (5 of 27): Md Abdul Quayum » assurejobs.com

6 months after the fact. (Sat 18 Nov 2006, 8:12 AM CST)

I was triying to solve this problem for 1 week, when srinivas give me this link in a group. It worked for me.
Thanks alot.
I am using the same AJAX to call a method on the server which sends a mail to the user.

my code if(status == 200) is evaluating to false yet the mail is
delivered. But because of the above status I am un able to display the
message to the user. Do any one hava an idea how to access
responseText or ResposeXML without status=200 because my prime target
is to display messages in the user interface.

I am returning action messages from my class, these action messages
need to be displayed in the user intrface. I am using spanElements and
replaceExistingElements to show these messages.
The problem is that the "req.status" is not becoming 200 in the
following code:

if (status == "ok" || status == "OK" || status == 200) { // OK response
reached now we can process the response
//Split the text response into Span elements
spanElements =
splitTextIntoSpan(req.responseText);
//Use these span elements to update the page
replaceExistingWithNewHtml(spanElements);
}
else {
alert("Problem with browser response:\n Response status "
req.statusText);
}

so, I am getting the alert even when the email is actually send.

alert("the length of returned text is "
req.responseText.length );
is 15178 where as
alert("responseXML " req.responseXML); is null

please suggest me how to solve this problem.

thanks:

Previous comment Return to entry

# (6 of 27): Matthom

6 months after the fact. (Sat 18 Nov 2006, 9:15 AM CST)

Md Abdul Quayum, I don't know why the status sometimes doesn't come across as 200, even though, as you said, it's clearly processing the server instructions just fine.

I have come across this many times. It is quite frustrating as I don't have a solution to it yet...

Previous comment Return to entry

# (7 of 27): Md Abdul Quayum » assurejobs.com

6 months, 1 week after the fact. (Sun 19 Nov 2006, 9:59 PM CST)

Dear Matthom,
I agree with you taht this is really frustrating that one do not get a result out of correct code. At the same time it is difficult to get the work done, because the same come is absolutely working fine for other module.
I am triying to intentionally put some errors in the code and diagnose the result. How far am I right.

Previous comment Return to entry

# (8 of 27): A.s.

7 months, 2 weeks after the fact. (Sat 30 Dec 2006, 7:41 AM CST)

I get different results:

When I call the ajax function from outside the form bounds via a

# (9 of 27): A.s.

7 months, 2 weeks after the fact. (Sat 30 Dec 2006, 7:44 AM CST)

I get different results: (sorry for the earlier entry - unintentional html re the button.)

When I call the ajax function from outside the form bounds via a button onClick, works OK.

When I call that function from inside - also via a button onClick ... - I get the error. The browser is invoking the form's action and method, cuz I put a crazy value in for the action, and it 404's on that value.

Any thoughts really, really appreciated.

Previous comment Return to entry

# (10 of 27): Matthom

7 months, 2 weeks after the fact. (Sat 30 Dec 2006, 8:15 AM CST)

A.S., what type of <input> element are you using?

Is it type="submit", or type="button"?

If it's submit, obviously it will try to use the form's action value.

Does that help?

Previous comment Return to entry

# (11 of 27): Md Abdul Quayum » assurejobs.com

7 months, 3 weeks after the fact. (Fri 05 Jan 2007, 10:19 PM CST)

A.S., what type of <input> element are you using?

Is it type="submit", or type="button"?

Using type="button" worked out for me.

Previous comment Return to entry

# (12 of 27): Kavorka

8 months after the fact. (Mon 15 Jan 2007, 2:19 AM CST)

thanks for your blog entry. in my case I was triggering from link ; I changed it to href="#" and it began to work.

Previous comment Return to entry

# (13 of 27): Adam

1 year after the fact. (Thu 31 May 2007, 12:51 AM CST)

you're a hero dude

Previous comment Return to entry

# (14 of 27): Sravanthi

1 year after the fact. (Mon 04 Jun 2007, 11:37 PM CST)

Many thanks. Really I struggled for this error two days. But with your simple solution made me free. Thanks.

Previous comment Return to entry

# (15 of 27): Paul

1 year, 1 month after the fact. (Wed 04 Jul 2007, 6:07 AM CST)

saved the day - an instance where firefox fails but ie works - was driving me mad

Previous comment Return to entry

# (16 of 27): Jpatiani » jpatiani.wordpress.com

1 year, 6 months after the fact. (Mon 10 Dec 2007, 5:08 AM CST)

wow, that very releasing. thanx, now my program work fine. the problem only change type from "submit" to "button". thanx

Previous comment Return to entry

# (17 of 27): Ranjan

1 year, 7 months after the fact. (Wed 02 Jan 2008, 2:44 PM CST)

Awesome...saved me hours. Thanks

Previous comment Return to entry

# (18 of 27): Odysseus

1 year, 7 months after the fact. (Tue 08 Jan 2008, 5:01 AM CST)

Your post was very helpfull in figuring out my problem. I had the same error, but my setup was a bit different.

I had a popup opened by a parent window. That popup used a callback function to submit something back to its parent window and after that it closed itself. The callback function was defined in the parent window, but was then assigned to a global variable in the popup dialog. So when the function was called, it ran in the scope of the popup dialog, but the AJAX/XMLHTTPRequest handler that it used was in the parent window. (I hope you can still follow me) After the popup dialog closed, the AJAX/XMLHTTPRequest call returned and failed on the status check. This had to do with the fact that the popup dialog wasnt there anymore (when i left the popup open, it did not fail). I fixed it by placing the code that did the AJAX-XMLHTTPRequest inside a setTimeout(). I think this broke the references to the scope of the popup dialog and placed it back in the parent window. After this fix the status check did not fail anymore.

Previous comment Return to entry

# (19 of 27): Peter » pixo.sk

1 year, 9 months after the fact. (Mon 11 Feb 2008, 9:49 PM CST)

Hi, I am getting the same error (I google you with that error text), but it is different problem since I don't use button to start XMLHttpRequest, but onload event to start a recursive function. So I make new XMLHttpRequest every one minute (to check new mails) via setTimeout().

Anyway... the error show up only occasionally. That means, request run just ok for example 20 times and then crash on that error, at the same line...

if (http_request.status==200) {...

I am not sure if this is not just Firefox problem, but if anyone have some information, please let me know.

Previous comment Return to entry

# (20 of 27): Odysseus

1 year, 9 months after the fact. (Tue 12 Feb 2008, 2:18 AM CST)

Peter,

does your error appear when you reload the page? If not can you post some more code?

Previous comment Return to entry

# (21 of 27): Peter » pixo.sk

1 year, 9 months after the fact. (Tue 12 Feb 2008, 6:27 AM CST)

Reloading the page fix the problem, but as I said, sometimes that error show up again.

code: function doRequest(k) { if(!titulka) getTitle(); document.title = '+ ' + titulka; // debug

var url = 'http://www.bombakseft.sk/ajax/posta.php;
var http_request = false;

if (window.XMLHttpRequest) {
    http_request = new XMLHttpRequest();
} else if (window.ActiveXObject) {
    try {
        http_request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            http_request = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
    }
}

if (!http_request) return false;
http_request.onreadystatechange = function() { spracuj(http_request, k); };
http_request.open('GET',url,true);
http_request.send(null);

}

function spracuj(httprequest, k) { if (httprequest.readyState==4) { if ((httprequest.status==200) || (httprequest.status==0)) { var pocet = httprequest.responseText * 1; if (pocet != 0) { document.title = '['+pocet+'] '+ titulka; document.getElementById('item06').className = 'active'; doPlay(); } else { setTitle(); document.getElementById('item06').className = ''; } } else { alert('ERROR, status: '+httprequest.status); } setTimeout('doRequest('+k+')', 60000); } }

note: There is some other functions and global variables declared out of this two functions, you can discover, but they are not involved in problem to be sure.

Previous comment Return to entry

# (22 of 27): Peter » pixo.sk

1 year, 9 months after the fact. (Tue 12 Feb 2008, 6:31 AM CST)

Oh... this is really mess comment html formating on this site, you should fix it dude.

Previous comment Return to entry

# (23 of 27): Odysseus

1 year, 9 months after the fact. (Tue 12 Feb 2008, 8:47 AM CST)

Hmm cant seem to find the reason for it. Maybe its just a glitch in the browser or something.

Previous comment Return to entry

# (24 of 27): Bal

1 year, 9 months after the fact. (Mon 18 Feb 2008, 7:59 PM CST)

Thanks for the post! it would have taken me days, if ever, to figure this out

Previous comment Return to entry

# (25 of 27): Kliment Stefanov

1 year, 10 months after the fact. (Thu 03 Apr 2008, 8:59 AM CST)

Another option is to use Synchronous XMLHttpRequest, which will preform both operations one after another.

Cheers,

Pimmy

Previous comment Return to entry

# (26 of 27): Bhj

2 years after the fact. (Thu 22 May 2008, 6:17 AM CST)

Cheers for the blog entry, i had a trigger prob too where i was making 2 ajax calls which were triggering the same thing! This entry helped me lots!

Previous comment Return to entry

# (27 of 27): Thomas Guymer » thomasguymer.co.uk

2 years after the fact. (Mon 02 Jun 2008, 9:33 AM CST)

Thanks for the post - very helpful!

Previous comment Return to entry

RSS feed for comments on this post

Leave feedback

Feedback

Input format: The editor controls below will assist with Markdown syntax.

Status

Sub-status

Your info

Return to entry.

matthom is published and produced by Matt Thommes - an independent publishing enthusiast, mobile blogger, content creator, informative writer, web developer from Chicago. Never one to conform, Matt intends to promote the effect the web has on our lives, in an effort to intensify, instruct, and clarify all that is happening around us.

Contact Matt

While doing some AJAX work this morning, I kept getting this error, which looks pretty scary.

You are at the feedback permalink page for: Scary AJAX error

Read more...