jQuery 如果可能,使用 AJAX 从 URL 获取 JSON 数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14149729/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 13:18:33  来源:igfitidea点击:

Get JSON data from URL using AJAX if possible

jqueryajaxjson

提问by user1947215

I want to get the JSON data from the URL below and use it in my webpage in any way possible, can it be done?

我想从下面的 URL 获取 JSON 数据并以任何可能的方式在我的网页中使用它,可以吗?

http://fantasy.premierleague.com/web/api/elements/100/

http://fantasy.premierleague.com/web/api/elements/100/

(Note I do not own this site, I'm just using the data for a simple free app.)

(注意我不拥有这个网站,我只是将数据用于一个简单的免费应用程序。)

If I simply enter the URL into the browser it works but that's no good as I want my page to use the data, so an AJAX request would be ideal but I cannot get it to work. I've tried using a jQuery AJAX call but cannot get it to work.

如果我只是在浏览器中输入 URL,它就可以工作,但这并不好,因为我希望我的页面使用数据,因此 AJAX 请求将是理想的,但我无法让它工作。我试过使用 jQuery AJAX 调用,但无法让它工作。

I'm staring to think it's not possible from within the browser and I would need to use Mechanize or something like that, which is not really an option.

我开始认为在浏览器中是不可能的,我需要使用 Mechanize 或类似的东西,这不是一个真正的选择。

Thanks.

谢谢。

回答by James Kleeh

I had this working, and now the error function is getting executed with a 200 status code. Is it possible they limit the number of queries per x seconds because it is working intermittently.

我有这个工作,现在错误函数正在以 200 状态代码执行。他们是否有可能限制每 x 秒的查询次数,因为它间歇性地工作。

Edit: Something is going on with their caching. Stuff is Hymaned.

编辑:他们的缓存正在发生一些事情。东西被劫持了。

$.ajax({
    type:"GET", 
    url: "http://fantasy.premierleague.com/web/api/elements/100/", 
    success: function(data) {
            $("body").append(JSON.stringify(data));
        }, 
    error: function(jqXHR, textStatus, errorThrown) {
            alert(jqXHR.status);
        },
   dataType: "jsonp"
});???????????????