首页 > 解决方案 > 由于 cors,来自 ajax 的 jsonp 解析错误,但 safari (14) 仍然在错误控制台中显示正确结果

问题描述

使用 jsonp 模式以这种方式绕过 CORS 限制:

function searchPubMed("rs1205") {
return $.ajax({
    url: 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi',
    dataType: 'jsonp',
    data: {
        db: 'pubmed',
        usehistory: 'y',
        term: term,
        retmode: 'json',
        retmax: 10
    }
});

}

根据控制台,这成功返回了记录,但有一个解析错误(意外的令牌':'):

{
"header": {
    "type": "esearch",
    "version": "0.3"
},
"esearchresult": {
    "count": "125",
    "retmax": "10",
    "retstart": "0",
    "querykey": "1",
    "webenv": "MCID_611764476e03297694413014",
    "idlist": [
        "34308116",
        "33707594",
        "33628645",
        "33584722",
        "33296257",
        "32769481",
        "32514365",
        "32477370",
        "32329054",
        "31959465"
    ],
    "translationset": [],
    "translationstack": [
        {
            "term": "rs1205[All Fields]",
            "field": "All Fields",
            "count": "125",
            "explode": "N"
        },
        "GROUP"
    ],
    "querytranslation": "rs1205[All Fields]"
}

}

如何解决解析错误?

标签: ajaxjsonp

解决方案


推荐阅读