Reputation: 33
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.
Upvotes: 0
Views: 659
Reputation: 5126
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: *');
Upvotes: 0
Reputation: 1373
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
Upvotes: 1