Permission denied to call method XMLHttpRequest.open in jQuery

Posted By  dotnetfish On 07 Sep 2010 10:09:43
emailbookmarkadd commentsprint
No of Views:4838
Bookmarked:0 times
Votes:0 times

Introduction

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; 

That's all, now problem in solved.Happy coding.

Sign Up to vote for this article
Other popular Tips/Tricks
Comments
By:DougDate Of Posted:6/3/2011 12:13:15 PM
Thank you
I'm not sure if I ever would have figured this out. without using location.host i was getting repeated "Permission Denied" and "Object Expected" errors. This fix did away with them all.
By:E.Date Of Posted:12/17/2010 6:12:20 AM
Super
wow this really helped me out! Thanks a lot.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top