简体   繁体   中英

Origin null is not allowed by Access-Control-Allow-Origin not working with jsonp

I searched, many answers here. But I tried it all, It still does not work for me. I want to to get json data from web service (cross domain).

var url1 = 'http://localhost:33219/iSes/Pro/RfsPro.svc/GetPro/';
$.getJSON(url1,function(json){
    alert('testing');
});

I got error from Chrome console Origin null is not allowed by Access-Control-Allow-Origin .

These are what I tried to do, by searching the answers here :

  1. Put /?callback=? to url :

     var url1 = 'http://localhost:33219/iSes/Pro/RfsPro.svc/GetPro/?callback=?'; 
  2. I found chrome.exe --allow-file-access-from-files but if we use this, do the clients that browse our website have to do it too?

  3. This answer, 3rd option related to CORS , using PHP to configure the header, How could I do this with ajax or jquery ? Because my project is using backbone.js not PHP .

While the source url and the destination url don't match you will always have this error!

You can't do an ajax request from "file:///E:/Project/WebSite/SourceWebsite/test.html" , to "http://yourdomain:33219/iSes/Pro/RfsPro.svc/GetPro/" , because it's a violation of the Same Origin Policy.

http://en.wikipedia.org/wiki/Same-origin_policy

You can do an ajax request to the server if and only if the protocol, url and port are the same.

If you want to access to : "http://yourdomain:33219/iSes/Pro/RfsPro.svc/GetPro/"

You must be at "http://yourdomain:33219/something"

I hope I made myself clear.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM