0

Here is my code

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

But when i run it i'm getting error.The jqXHR.status is 0 , textStatus is Error and errorThrown is No Transport

1

2 Answers 2

2

You can try using Yahoos YQL as JSONP proxy. http://developer.yahoo.com/yql/

$.getJSON("http://query.yahooapis.com/v1/public/yql", {
    q: "select * from json where url=\"http://fantasy.premierleague.com/web/api/elements/100/\"",
    format: "json"
},

function (data) {
    console.log(data.query.results.json.transfers_out);
});

http://jsfiddle.net/zZy77/

Sign up to request clarification or add additional context in comments.

Comments

1

This is not possible because you're trying to make cross-domain request.

you might want to check out JSONP as a solution instead.

Check out this http://remysharp.com/2007/10/08/what-is-jsonp/

5 Comments

Updated the answer with link
but to use jsonp i need to modify the json output of the external site too rite?but i dont have control over the external site
Yes, you need to wrap JSON response in a function if you don't have access then consider using proxy.
is it possible to do using javascript only?
CORS is another option as mentioned above. jQuery.support.cors = true;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.