javascript - XmlHttpRequest error: Origin null is not allowed by Access-Control-Allow-Origin -
I am developing a page that draws pictures through jQuery's AJAX support from Flickr and Panoramas.
Flickr is working fine, but when I XMLHttpRequest can not load. Original tap is not allowed by access-control-permission-origin. If I ask the URL directly from the browser, then it works fine, what is going on, and can I find around it? Am I writing my query incorrectly or is it something that interferes with what I'm trying to do to Panoramium? Google did not turn on any useful mail. Edit Here is some sample code that shows a problem: You can. Edit 2 Thanks to Darin for helping him with this. The above code is incorrect. Instead, use: $ I try to get (url, callback) from Panoram, then I see an error in Chrome's console:
$ (). Ready (function () {var url = 'http: //www.panoramio.com/wapi/data/get_photos?v=1&key=dummykey&tag=test&offset=0&length=20&callback=processImages& Minx = -30 & amp; miny = 0 & amp; maxx = 0 & amp; Maxy = 150 '; $ .get (url, function (jsonp) {var process image = function (data) {warning (' OK ');}; eval (jsonp );});});
$ (). Ready (work () {var url = 'http://www.panoramio.com/appi/data/get_photos?v=1 & amp; key = dummy & amp = tag = test and offset = 0 & length = 20 & amp; minx = -30 & amp; miny = 0 & amp; maxx = 0 & amp; maxy = 150 & amp; callback =? & # .get (url, function (data) {// 'data' Can be used here ...});}); For the record, as far as I can tell, you have two problems:
-
You can get your
$ The "jsonp" type specifier was not going in Get
, so it was using a normal XMLHttpRequest However, if your server has fixed it, then your browser to allow cross-domain XMLHttpRequest CORS (Cross-origin resource sharing)Access-Control-Permission-Origin
header came in. -
I believe that you have mentioned that you are running it from the file: // URL. There are two ways for the CORS header to indicate that a cross-domain XHR is OK. One has to send the
access-control-permission-origin: *
(if you had access to Flickr through$ .make it
, they would be doing it) while others However,file: //
url generates a zerogenerator
, to echo back to the content of theoriginal
header, which is the echo back Can not be authorized by.
To use Darin's suggestion, $. GetJSON
was used in the first roundabout manner. Looking at the sub-code callback =
in the URL, the magic from "Jason" to "JasonCP" has a little magic to change the request type.
Second, a CORS is not trying to request a URL from a file: //
.
To clarify to others, here are the general troubleshooting instructions:
- If you are trying to use JSONP, make sure that the following There is one of the cases:
- You can change the
$. Are using
andJsonp
. - Are you using
$ .getJSON
and in the URLcallback =?
are included.
- You can change the
- If you are trying to do cross-domain XMLHttpRequest through CORS ...
- Make sure that you
http: / /
. The scripts running throughfile: //
have limited support for CORS. - Make sure the browser (Opera and Internet Explorer is late for the party)
- Make sure that you
Comments
Post a Comment