Pages

Search This Blog

Monday, November 5, 2007

jQuery: Exception... "'Permission denied to call method XMLHttpRequest.open' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: ...

I received below error message in firebug when i try to use jQuery Ajax call

var html = $.ajax({
url: "http://www.xxx.com",
async: false
}).responseText;

Where http://www.xxx.com is different domain from my current site.

Exception... "'Permission denied to call method XMLHttpRequest.open' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)" location: "" data: no]

As far as my understanding, this is not allowed. In order to have the similar result, use Cross Domain getJSON or you can check on my sample in other post which work on cross domain ajax.




Ajax treat http://www.xxx.com and http://xxx.com as two different entry. There are different between url with www and without www. To solve this problem, use location.host to get the url that use by visitors.

example:
var html = $.ajax({
url: "http://"+location.host+ "/Realtime.ashx" + "?PostID=" + PostID,
async: false
}).responseText;


6 comments:

Anonymous said...

Hey thanks! This helped me spot a stupid mistake that was taking me ages to figure out.

- Aaron (dev.wuggawoo.co.uk);

Eduan Lenine said...

rapaz vc tirou um peso de minha consciencia!
guy, thank you, i never would discovery this, lol!!!

Anonymous said...

Great info.. this one had me puzzled. Thanks !!!

Anonymous said...

Tried it manually to get domain url right. No success. But "location.host" did it. Thanks!

Anonymous said...

Muchos Gracias!

indeed, www.mydomain.com is different from mydomain.com , Jquery cant run when you get these things wrong

Anonymous said...

thanks you