2

I am trying to pull data using a small script I found that seems to work with any other url that produces json data, however when I use it with a url that ends in .json, i will just receive a syntax error.

//error

Uncaught SyntaxError: Unexpected token : http://frontier.ffxiv.com/worldStatus/gate_status.json?callback=jQuery21309476937903091311_1450254419566&q=select+title%2Cabstract%2Curl+from+search.news+where+query%3D%22cat%22&format=json&_=1450254419567

//code below

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

<script>
// Using YQL and JSONP
$.ajax({
    url: "http://frontier.ffxiv.com/worldStatus/gate_status.json",

    // The name of the callback parameter, as specified by the YQL service
    jsonp: "callback",

    // Tell jQuery we're expecting JSONP
    dataType: "jsonp",

    // Tell YQL what we want and that we want JSON
    data: {
        q: "select title,abstract,url from search.news where query=\"cat\"",
        format: "json"
    },

    // Work with the response
    success: function( response ) {
        console.log( response ); // server response
    }
});
</script>
3
  • 2
    what is the error on console? Commented Dec 16, 2015 at 8:29
  • 1
    I've added the error into the description, sorry. Commented Dec 16, 2015 at 8:30
  • 1
    Use datatype json instead of jsonp Commented Dec 16, 2015 at 8:35

1 Answer 1

5

The URL you're doing the ajax request to doesn't deliver JSONP, just regular JSON.

You get a parse error because the result is something like

{"status":0}

while jQuery expects something like

callback({"status":0})

Unfortunately it doesn't look like CORS is supported either, so the data from that URL can't be gotten from the clientside, due to the same-origin policy.

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

1 Comment

Sure, if you control the server on ffxiv.com you add the appropriate Access headers. If you don't control the server on ffxiv.com there's nothing you can do, you'd have to write a serverside script to get the data, and then use ajax to run the serverside script on your own server.

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.