Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.1k views
in Technique[技术] by (71.8m points)

jquery - 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 happen here is my code.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...