JSONP returning "Uncaught SyntaxError: Unexpected token :"

This question already has an answer here:

  • json Uncaught SyntaxError: Unexpected token : 4 answers

  • I'm guessing you have omitted some of the code.

    First, when Chrome give you that error, you can click on it in the console window and it will show you the exact line that the error is being thrown.

    Also, it seems like your code is a little more verbose than it need be.

    $.ajax({
            type: "GET",
            dataType: "jsonp",
            url: "http://divvybikes.com/stations/json",
            success: function (data) {
                console.log(data);
            }
        });
    

    The return type should be JSONP but its currently returning JSON

    example

    //JSON
    {"name":"abc","id":0}
    
    //JSONP format
    func({"name":"def","id":1});
    

    also ensure that the JSON returned is valid.


    Copy the returned json. Open http://jsonlint.com/

    Paste your whole json there and validate. You may find issues with your json returned. Get that right and try again

    链接地址: http://www.djcxy.com/p/46012.html

    上一篇: AJAX调用返回GET请求上的意外标记ILLEGAL

    下一篇: JSONP返回“未捕获的SyntaxError:意外的令牌:”