修改getJSON以与CORS一起使用 [英] modify getJSON to work with CORS
问题描述
我正在寻找允许使用$ .getJSON进行跨域访问的方法.我遇到了一些解决方案,这些解决方案表明使用CORS是解决此问题的方法.但是大多数解决方案都具有通用的ajax格式.
I am looking for ways to allow cross-domain access using $.getJSON. I came across solutions which suggest that using CORS is the solution to this problem. But most of the solutions have a general ajax format.
我无法使用JSONP,因为我从无法访问的服务器获取数据.有没有一种方法可以使用$ .getJSON修改此代码以获取数据?
I cannot use JSONP since I get data from a server which I do not have access. Is there a way to modify this code using $.getJSON to get the data?
$.getJSON(jsonURL, function(res){
console.log(JSON.stringify(res));
});
还是必须将Ajax格式用于CORS?
Or do I have to use ajax format for CORS?
推荐答案
我没有访问权限的服务器
Server which I do not have access
我认为,这会伤到你的脖子.
您需要某种访问服务器的权限或与拥有该权限的人联系.至少您必须调整HTTP-Header
才能输入域,Access-Control-Allow-Origin
是关键字.
I think, this will break your neck.
You need some kind of access to the server or contact someone who has. At least you have to adjust the HTTP-Header
to enter your domain Access-Control-Allow-Origin
is the keyword.
看看 MDN
这篇关于修改getJSON以与CORS一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!