“SyntaxError: Unexpected token : ” zipcodeapi example JSONP

北慕城南 提交于 2019-12-24 06:49:37

问题


  $.ajax({
    url:"https://www.zipcodeapi.com/rest/kQvPAFvKlaGM1g2SoOzWcGoK0auNuT2PKyEle95zjMll2odrcMootN8tXDhsxkhh/radius.json/20151/5/mile",
            jsonp: "callback",
            dataType: "jsonp",
            data: {
                format: "json"
            },
            success: function( response ) {
                console.log( response ); 
            }
        });  

I am having a problem with making an ajax call through my localhost. I was wondering why I am getting the error "SyntaxError: Unexpected token : ". Can someone please help me out? Thanks!


回答1:


You need to set up the client-side access on https://www.zipcodeapi.com

If you select the "App Management" section and enter your details you should be able to enter your domain name.

The only way to get this working locally will be to set up a local webserver and if this is running on localhost, enter localhost as one of the domains.




回答2:


Seems like jsonp is not working correctly. Try json instead

$.ajax({
    url:"//www.zipcodeapi.com/rest/kQvPAFvKlaGM1g2SoOzWcGoK0auNuT2PKyEle95zjMll2odrcMootN8tXDhsxkhh/radius.json/20151/5/mile",
            dataType: "json",
            data: {
                format: "json"
            },
            success: function( response ) {
                console.log( response ); 
            }
        });


来源:https://stackoverflow.com/questions/38677498/syntaxerror-unexpected-token-zipcodeapi-example-jsonp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!