2

I am trying to get a json response from the comicvine api but am getting the following error. comicvine.gamespot.com/:1 Uncaught SyntaxError: Unexpected token :

I see my json result, formatted, in the response body but am getting the console error above.

export function getSeriesFromComicVine() {
  const url = "http://comicvine.gamespot.com/api/characters/?api_key=f18c6362ec6d4c0d7b6d550f36478c1cd6c04a49&filter=gender:male,name:hawkeye&format=json&callback=?";
  $.ajax({
    url: url,
    // data: {test: "test"},
    type: 'GET',
    crossDomain: true,
    jsonpCallback: 'callback',
    dataType: 'jsonp',
    jsonp: false,
    jsonpCallback: "myJsonMethod"
    success: function (data) {
    console.log(data);
     }
  });
}
6
  • I see my json result, formatted - but is it valid (computer says no), in the response header - surely it's in the response body! Commented Jun 15, 2017 at 1:46
  • can you see that the response is indeed JSON - but not JSONP - looks like comicvine.gamespot.com doesn't do JSONP Commented Jun 15, 2017 at 1:48
  • Well I am getting the response. And all of the examples that I have seen have used jsonp. I will add the response I am getting in the question. Commented Jun 15, 2017 at 1:50
  • well, you must be doing something wrong, because the response is JSON, not JSONP Commented Jun 15, 2017 at 1:50
  • Yes. I assumed I was doing something wrong. Any idea of what though? When I have regular json as my datatype, I get the cross origin error. Commented Jun 15, 2017 at 1:53

1 Answer 1

2

You need to set format=jsonp not json

the jsonp callback parameter name needs to be json_callback according to comicvine.gamespot.com - I found this out by going to url https://comicvine.gamespot.com/api/characters/?api_key=[your api key]&filter=gender:male,name:hawkeye&format=jsonp in the browser, and it told me what was missing - very friendly API - the response had an error value

"'jsonp' format requires a 'json_callback' argument"

and no need for callback=? in the url - seeing as jquery adds the callback parameter and it isn't named callback

function getSeriesFromComicVine() {
    const url = "https://comicvine.gamespot.com/api/characters/?api_key=[your api key]&filter=gender:male,name:hawkeye&format=jsonp";
    $.ajax({
        url: url,
        type: 'GET',
        dataType: 'jsonp',
        jsonp: "json_callback",
        success: function (data) {
            console.log(data);
        }
    });
}
Sign up to request clarification or add additional context in comments.

Comments

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.