jQuery.getJSON - Access-Control-Allow-Origin问题 [英] jQuery.getJSON - Access-Control-Allow-Origin Issue

查看:438
本文介绍了jQuery.getJSON - Access-Control-Allow-Origin问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery的 $。getJSON()函数来返回一组简短的JSON数据。

I'm jusing jQuery's $.getJSON() function to return a short set of JSON data.

我已经将JSON数据放在网址上,例如 example.com
我没有意识到,但是当我访问同一个url时,无法加载JSON数据。我按照控制台进行操作,发现由于 Access-Control-Allow-Origin XMLHttpRequest 无法加载。

I've got the JSON data sitting on a url such as example.com. I didn't realize it, but as I was accessing that same url, the JSON data couldn't be loaded. I followed through the console and found that XMLHttpRequest couldn't load due to Access-Control-Allow-Origin.

现在,我已经读完了,很多网站只是说使用 $。getJSON()和这将是解决方法,但显然它没有用。我应该在标题或函数中更改一些内容吗?

Now, I've read through, a lot of sites that just said to use $.getJSON() and that would be the work around, but obviously it didn't work. Is there something I should change in the headers or in the function?

非常感谢帮助。

推荐答案

这很简单,使用 $。getJSON()函数,在你的URL中只包括

It's simple, use $.getJSON() function and in your URL just include


callback =?

callback=?

作为参数。这会将调用转换为进行跨域调用所必需的JSONP。更多信息: http://api.jquery.com/jQuery.getJSON/

as a parameter. That will convert the call to JSONP which is necessary to make cross-domain calls. More info: http://api.jquery.com/jQuery.getJSON/

这篇关于jQuery.getJSON - Access-Control-Allow-Origin问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆