Ajax: IE and Mozilla Errors you need to know about

來源:互聯網
上載者:User
 

If you are logging clientside errors, your may see two errors show up with Ajax applications. The first error is with IE: "Automation server can't create object" and the second error was Mozilla: "NS_ERROR_NOT_AVAILABLE". Now I will tell you what causes them. Automation server can't create object

Well this error commonly will show up with IE6.0 in your logs. This is a really simple error to reproduce. Set your security level to high and then enable active scripting (JavaScript). Run your application. If you get an error, that means you are not using try catches when you are setting the ActiveX object. So if you see this error you just need to add try catches around your declaration. Basic example is below:

try{      this.req=new ActiveXObject("Microsoft.XMLHTTP");    }catch(e){}
NS_ERROR_NOT_AVAILABLE

This error took a little investigation on my part. So I did a search on bugzilla and came up with this link:https://bugzilla.mozilla.org/show_bug.cgi?id=238559#c0

So you do not have to search through the whole page I posted the problem with Mozilla and why it causes the error:

<quote from https://bugzilla.mozilla.org/show_bug.cgi?id=238559#c0>

Mozilla calls onload() for all HTTP transactions that succeeded. The onlytime it calls onerror() is when a network error happened. Inside the onerrorhandler, accessing the status attribute results in this exception:Error: [Exception... "Component returned failure code: 0x80040111(NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]"  nsresult: "0x80040111(NS_ERROR_NOT_AVAILABLE)"  location: "JS frame ::file:///Users/chuck/errtest.html :: anonymous :: line 114"  data: no]Source File: file:///Users/chuck/errtest.htmlLine: 114
</quote>

Now an easy fix for now is to add another try catch in your onerror function when you are reading the status property. This will stop the error occuring, but thanks to this, you will not have all of the information that you could have with IE. Error Handling

On of the best things you can do is implement error handling on your clientside applications. Logging them to the server can let you spot problems that you may never see. You may never new about these errors on your site if they never came up in testing. Logging problems will allow you to see them. I am doing a talk on this at The Ajax Experience in May.



Eric Pascarello
Coauthor of Ajax In Action
Moderator of HTML/JavaScript at www.JavaRanch.com
Author of: JavaScript: Your Visual Blueprint for Dynamic Web Pages TrackBacks[0] Comments[10] Posted by pascarello on February 7, 2006 3:51:11 PM EST
Reply | Permalink Re: Ajax: IE and Mozilla Errors you need to know about Hi Eric, I read your interview about security issues with AJAX. I share your view that overloading client JavaScript not only slows down response, but may expose a major part of presentation & business logic to outside. We implemented an AJAX catalog where all business and presentation logic lives on the server. Client javascript is standard for any form, control, event or value. It simply executes presentation directives contained in server's responses. I suggest you quote this application during The Ajax Experience conference in May. Thierry Nivelet Comment from Thierry Nivelet on February 8, 2006 4:33:10 AM EST Reply | Permalink Re: Ajax: IE and Mozilla Errors you need to know about Hi Eric, I noticed a difference between IE and Mozilla with innerHTML. It looks like innerHTML content length is limited in Mozilla. On our AJAX catalogue, when clicking a product button like "Eclairage", we come up with a DIV filled with HTML provided by the server: displays OK with IE, truncated with Mozilla. Thierry Nivelet Comment from Thierry Nivelet on February 8, 2006 4:37:46 AM EST Reply | Permalink Re: Ajax: IE and Mozilla Errors you need to know about a reply 1 year later :) Hi Eric, I noticed a difference between IE and Mozilla with innerHTML. It looks like innerHTML content length is limited in Mozilla. the problem with mozilla seems not to be on innerHTML, but accessing XML DOM element's contents. I've resolved the problem by not using XML as response, but a plain/text reply, and use .responseText instead of getting an elements contents from .responseXML well, in fact i've had other information than the html data that i should transmit, and i've used JSON for both other data and the html string. Comment from Kerem HADIMLI on February 10, 2007 3:26:11 PM EST Reply | Permalink Re: Ajax: IE and Mozilla Errors you need to know about Hey Eric, I have the error in Firefox, but I don't understand your solution (because i'm not that smart i ques....). Can you maybe explain a little about what code I should add or remove. I don't have a onerror function or I didn't made it. And what is a 'try catch'? I would be verry thankfull if you could explain some of this to me! Bye, Rik Comment from Rik on April 27, 2006 7:50:23 AM EST Reply | Permalink Re: Ajax: IE and Mozilla Errors you need to know about Basic idea:

var status = "";try{  status = yourXHRVariable.statusText;    }catch(e){  status = "Trouble accessing it";}
Eric Comment from Eric Pascarello on April 27, 2006 9:18:44 AM EST Reply | Permalink Re: Ajax: IE and Mozilla Errors you need to know about Cool! It works ! Thanks a lot! Comment from Anonymous on June 18, 2006 2:28:19 PM EST Reply | Permalink Re: Ajax: IE and Mozilla Errors you need to know about What do you do about this error: (NS_ERROR_NOT_INITIALIZED) [nsIXMLHttpRequest.send] This happens whenever I put a timeout on the ajax timeoutId = setTimeout( function() { if ( callInProgress(http) ) { http.abort(); return false; //alert("TIMEDOUT"); } }, 200 // Five seconds ); Yes 200 purposely just to see the response Comment from Anonymous on October 14, 2006 5:21:00 AM EST Reply | Permalink Re: Ajax: IE and Mozilla Errors you need to know about Hello, I am developing a web page which contain slider and a checkbox. Now when first I move the slider the btnclick is called in javascript onchange function of the slider. After moving the slider when I click the checkbox it calls it SelectedIndexChanged function. The Check box is in UpdatePanel. Now the problem occurs when I first click the check box it works fine but after that when I move the slider it does not calls the btnclick. This problem occues in FireFox and Netsacpe. In IE it works fine. In the Error consol I get the following error message Error: [Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: http://localhost:4749/User/ScriptResource.axd?d=tHQt-oPWNlRi7os_OyOsDAKzDzf7ngBw_iN5s3Vz7NSS8drfIXqGHEPcxWRrECSUnndCTIXAJ80AoilyKeP-eL0S8ZICFQER3CW1q4QzioE1&t=633029062313675 134 :: Sys$Net$XMLHttpExecutor$get_statusCode :: line 4285" data: no] Source File: http://localhost:4749/User/ScriptResource.axd?d=tHQt-oPWNlRi7os_OyOsDAKzDzf7ngBw_iN5s3Vz7NSS8drfIXqGHEPcxWRrECSUnndCTIXAJ80AoilyKeP-eL0S8ZICFQER3CW1q4QzioE1&t=633029062313675 134 Line: 4285 On line 4285 there in no javascript error. Is this a bug in FireFox ??? Comment from Deepesh on April 5, 2007 8:50:56 AM EST Reply | Permalink Re: Ajax: IE and Mozilla Errors you need to know about Thanks a lot! Comment from Kevinin on April 18, 2007 9:44:30 AM EST Reply | Permalink Re: Ajax: IE and Mozilla Errors you need to know about To fix this problem, try making a setTimeout(functionsthatmakestheAjaxSend(),500); Adjust the time as you like. Good luck Comment from gonxalo on May 14, 2007 9:38:08 AM EST

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.