4

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..?

Umesh Kadam
  • 843
  • 2
  • 7
  • 14

3 Answers3

2

After Google for the same, I came to know that, user have to add "" in config.xml of the phonegap/hybrid application.

Umesh Kadam
  • 843
  • 2
  • 7
  • 14
1

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/
Tom
  • 43,583
  • 4
  • 41
  • 61
1

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.

Community
  • 1
  • 1
palmplam
  • 707
  • 9
  • 20