如果可能,使用AJAX从URL获取JSON数据 [英] Get JSON data from URL using AJAX if possible

查看:251
本文介绍了如果可能,使用AJAX从URL获取JSON数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

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.)

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

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.

我一直在想从浏览器内部是不可能的,我将需要使用Mechanize或类似的东西,这实际上不是一个选择.

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.

谢谢.

推荐答案

我已经完成了这项工作,现在错误函数正在使用200状态代码执行.因为它是间歇性地工作,所以它们是否有可能限制每x秒的查询数量.

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.

它们的缓存正在进行中.东西被塞住了.

Something is going on with their caching. Stuff is jacked.

$.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"
});​​​​​​​​​​​​​​​

这篇关于如果可能,使用AJAX从URL获取JSON数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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