开发者

Error 'Origin is not allowed by Access-Control-Allow-Origin' while using $.getJSON

I am using jquery $.getJSON and keep getting the following error.

Origin http://example.co.uk is not allowed by Access-Control-Allow-Origin.

The issue i am having is it was working fine then suddenly started to do this any reason why this might happe开发者_开发问答n here is my code.

http://jsfiddle.net/isimpledesign/KnUBH/


You get this error when you try to make a request from your site to a site on a different domain (or sub-domain). It is possible to configure the other site to allow you to make requests (see Mozilla documentation), although this feature is not supported everywhere.

An alternative to normal AJAX calls is JSONP, which requires the server to support it but doesn't have cross-domain restrictions. It turns out that Blogger does support this, so you just need to modify the URL to

var url = 'http://isimpledesign.blogspot.com/feeds/posts/default?alt=json&callback=?'

and jQuery will handle it properly. (Fiddle)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜