0

I have a Web service URL on request it will return an XML response. When i directly post the URL in the browser i am getting the response. But when i do an AJAX call it fails.

Chrome Error: Origin null is not allowed by Access-Control-Allow-Origin.

Firefox Error: XML Parsing Error: no element found Location: moz-nullprincipal:{e0bbb28b-e8ae-4b43-a266-428a24f9278d} Line Number 1, Column 1.

All the params like username,password query string are passed in the webservice URL.

Apologies: I cannot post the code and the URL.

Any help is greatly appreciated.

Sanath
  • 33
  • 7
  • If you can't post anything, you'd better go to some search engine with " Origin null is not allowed by Access-Control-Allow-Origin" and maybe end-up to some interesting content like http://stackoverflow.com/a/8456586/1236044 – jbl Sep 20 '13 at 07:39
  • 1
    If you want help, you're going to have to post the code. – Ant P Sep 20 '13 at 07:42
  • Check out this answer: http://stackoverflow.com/questions/17618401/how-to-load-an-external-xml-from-javascript/18193257#answer-18193257 – public override Sep 20 '13 at 07:46

2 Answers2

1

You are trying to run AJAX to a different domain (also known as cross-domain AJAX). This works when you're running directly from the browser because there's no cross domain restriction when doing that.

Solutions: - Use CORS (http://en.wikipedia.org/wiki/Cross-origin_resource_sharing) - Use JSONP (http://en.wikipedia.org/wiki/JSONP) - USe proxy on the server side

Related questions: - CORS - Cross-Domain AJAX Without JSONP By Allowing Origin On Server

Community
  • 1
  • 1
Gabi Lee
  • 1,193
  • 8
  • 13
0

Fix for client side code:

If you are sending a $.get request, you need to pass Data-Type as 'jsonp' for cross domain AJAX get.

You may also try $.getJSON method. You can read more in The jQuery Cross-Domain Ajax Guide.

OR

Fix for server side code:

You may enable cross domain serving, eg. in PHP

header('Access-Control-Allow-Origin: *');
Sunny R Gupta
  • 5,026
  • 1
  • 31
  • 40