Scary AJAX error May15 '06

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

Error: [Exception... "Component returned failure code: 0x80040111 (NSERRORNOTAVAILABLE) [nsIXMLHttpRequest.status]" nsresult: "0x80040111 (NSERRORNOTAVAILABLE)" location: "JS frame :: http://192.168.3.16/liso/javascript/servicerep.js :: checkNameStateChange :: line 50" data: no] Source File: http://192.168.3.16/liso/javascript/servicerep.js Line: 50

Ugly, eh? Yuck.

It was "tripping up" on the line in my JavaScript that began like this:

if (xmlHttp.status == 200)

Now why would it stop there?

Anyone familiar with AJAX would recognize that line as the "check" for data that’s been returned from a remote server call. In other words, if our remote server call returns data, the status would be 200. If not, the status would be 204, which means No Content.

I was positive the remote call returned data, because I checked the query myself.

Turns out my problem had to do with the "trigger" that initially began the AJAX request.

The "trigger" is an HTML form button, which looked like this:

<input type="submit" id="addbutton" value="Add New Account" />

This is just a simple "form submit" button.

However, it doesn’t actually submit the form through the action attribute in the <form> element. Rather, I use the id attribute, "addbutton", to grab the "click" event.

Long story short (I think I already made this too long), I had to change the submit button to this:

<input type="button" id="addbutton" value="Add New Account" />

You see, it was trying to submit the form, at the same time as running the AJAX call, behind the scenes. By changing the <input> element to a button, this resolved the problem.

So, to sum this jibberish up - if you ever see that error - check your "trigger."

Categories: JavaScript , Tips

Add Feedback (view all)

Leave feedback

Feedback

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

Status

Sub-status

Your info

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 inpu ... Read more.

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

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

Damn, this was the solution i was looking for. I had a problem in Firefox that uses an image button (ASP.NET) and once ... Read more.

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 t ... Read more.

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 processi ... Read more.

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 diff ... Read more.

I get different results: When I call the ajax function from outside the form bounds via a ... Read more.

I get different results: (sorry for the earlier entry - unintentional html re the button.) When I call the ajax function from outside the f ... Read more.

A.S., what type of <input> element are you using? Is it type="submit", or type="button"? ... Read more.

A.S., what type of <input> element are you using? Is it type="submit", or type="button" ... Read more.

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

you're a hero dude ... Read more.

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

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

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

Awesome...saved me hours. Thanks ... Read more.

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 ... Read more.

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, ... Read more.

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

Reloading the page fix the problem, but as I said, sometimes that error show up again. code: function doRequest(k) { if(!titulka ... Read more.

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

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

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

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

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 ... Read more.

Thanks for the post - very helpful! ... Read more.

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

Similar Entries

Stats

565 unique visits since August 2008

Syndicate

Advertisements