Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others


0 votes
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.


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 Vigges Developer Community for programmer and developer-Open, Learning and Share