Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/428.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript $.ajax和JSONP.uncaughtsyntaxerror:意外标记<;_Javascript_Jquery_Ajax_Jsonp - Fatal编程技术网

Javascript $.ajax和JSONP.uncaughtsyntaxerror:意外标记<;

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

我一直收到一个未捕获的SyntaxError:API不支持jsonp的意外标记。您使用的URL用于API的文档,而不是API本身。也不支持CORS。。。因此,我不认为您可以使用ajax调用从客户端(浏览器)使用API。API调用应该看起来像一个可能的解决方案,即确保web服务器充当代理,并将ajax请求发送到服务器,服务器将向远程源发送请求并收集其响应,然后将其发送回客户端
    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": ""
}