Using client-side REST APIs using jQuery for a telephone application

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 am trying to access the REST API from the client side using jQuery, but it gives an error like XMLHttpRequest cannot load <Web Service URL>. Origin null is not allowed by Access-Control-Allow-Origin. XMLHttpRequest cannot load <Web Service URL>. Origin null is not allowed by Access-Control-Allow-Origin.

So can someone help me solve this error ??

+4
source share
3 answers

After Google did the same, I found out that the user must add a "" to the config.xml of the phonegap / hybrid application.

+2
source

Ajax requests must be on the server that served the web page.

What you can do is have a proxy server on your website that forwards requests from the browser to the site you want to call.

http://your.site.here/proxy/bentley/LearnService/Learnservice.svc/REST/ ...

So, if you used apache, for example, you can configure the reverse proxy by adding something like httpd.conf below:

 ProxyPassReverse /proxy/bentley http://khara37793punl.bentley.com/ 
+1
source

Take a look at other SO issues with this issue: Access Control Allow Origin Not Allowed

And the famous: Access-Control-Allow-Origin Multiple domains of origin?

Everyone explained these answers, you must allow the script to your server, or your script must be on the same server.

+1
source

Source: https://habr.com/ru/post/1437519/


All Articles