问题
$.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