Reputation: 883
My code is like
$.ajax({
cache: false,
url: <Web Service URL>,
data: "{}",
type: 'GET',
crossDomain: true,
dataType: 'json',
success: function() { alert("Success"); },
error: function() { alert('Failed!'); },
});
I'm trying to access the REST API from client side using JQuery but it gives error like
XMLHttpRequest cannot load <Web Service URL>. Origin null is not allowed by Access-Control-Allow-Origin.
So may someone help me to resolve this error..?
Upvotes: 4
Views: 2250
Reputation: 883
After Google for the same, I came to know that, user have to add "" in config.xml of the phonegap/hybrid application.
Upvotes: 2
Reputation: 717
Take a look on other SO questions with this problem : Access Control Allow Origin not allowed by
And the famous : Access-Control-Allow-Origin Multiple Origin Domains?
All was explain on these answers, you have to allow script your server, or your script has to be on the same server.
Upvotes: 1
Reputation: 44821
Ajax requests need to be to the the server that served the web page.
What you can do is have a proxy on your website that forwards requests from the browser to the site to which you wish to make the call.
http://your.site.here/proxy/bentley/LearnService/Learnservice.svc/REST/...
So if you happened to be using apache for instance you could configure a reverse proxy by adding something like below to httpd.conf:
ProxyPassReverse /proxy/bentley http://khara37793punl.bentley.com/
Upvotes: 1