Javascript $.ajax和JSONP.uncaughtsyntaxerror:意外标记<;
我一直收到一个未捕获的SyntaxError:API不支持jsonp的意外标记。您使用的URL用于API的文档,而不是API本身。也不支持CORS。。。因此,我不认为您可以使用ajax调用从客户端(浏览器)使用API。API调用应该看起来像一个可能的解决方案,即确保web服务器充当代理,并将ajax请求发送到服务器,服务器将向远程源发送请求并收集其响应,然后将其发送回客户端Javascript $.ajax和JSONP.uncaughtsyntaxerror:意外标记<;,javascript,jquery,ajax,jsonp,Javascript,Jquery,Ajax,Jsonp,我一直收到一个未捕获的SyntaxError:API不支持jsonp的意外标记。您使用的URL用于API的文档,而不是API本身。也不支持CORS。。。因此,我不认为您可以使用ajax调用从客户端(浏览器)使用API。API调用应该看起来像一个可能的解决方案,即确保web服务器充当代理,并将ajax请求发送到服务器,服务器将向远程源发送请求并收集其响应,然后将其发送回客户端 function democracyMap(resp) { representative.fullName
function democracyMap(resp) {
representative.fullName = resp.jurisdictions[5].elected_office[0].name_full;
representative.face = resp.jurisdictions[5].elected_office[0].url_photo;
representative.district = resp.jurisdictions[5].name;
senator1.fullName = resp.jurisdictions[6].elected_office[0].name_full;
senator1.face = resp.jurisdictions[6].elected_office[0].url_photo;
senator2.fullName = resp.jurisdictions[6].elected_office[1].name_full;
senator2.face = resp.jurisdictions[6].elected_office[1].url_photo;
representativeInfo();
senator1Info();
senator2Info();
apiSuccess();
}
function ajaxFail(req, status, err) {
console.log('something went wrong', status, err);
}
function getDemocracyMap(){
$.ajax({
type: "GET",
url: "http://api.democracymap.org/",
data:"location=",
crossDomain: true,
dataType: "jsonp",
success: function(resp) {
democracyMap(resp);
},
error: ajaxFail
});
}
var representative = {
"fullName": "",
"firstName": "",
"lastName": "",
"district": "",
"face": "",
"party": "",
"termStart": "",
"termEnd": "",
"facebookID": "",
"twitter": "",
"youTube": ""
}