我正在使用$ .ajax向https服務器準備的api發送jsonp請求。jsonp請求中未定義的responseText
我的腳本如下:
var sUrl = "https://localhost/api/" + document.getElementById('query').value +
"?apikey=c13eb63d-b9ee-4ceb-89fe-944072deddbb&fmt=json&limit=&query=" + document.getElementById('query').value;
$.ajax({
type: 'GET',
url: sUrl,
dataType: 'jsonp',
jsonp: false,
async:false,
crossDomain : true,
complete: function(jqXHR, textStatus){
alert(jqXHR);
alert(jqXHR.responseText);
}
});
我的請求將被髮送,我可以在我的瀏覽器中收到的結果,這是我的迴應主體:
{「relatedid_restriction」:空」目的 「:」 減輕」, 「ASN」:NULL, 「RIR」:NULL, 「alternativeid」:空, 「CC」:NULL, 「detecttime」: 「2014-04-08T17:34:31Z」, 「地址」 : 「google.com」, 「alternativeid_restriction」:空, 「ID」: 「2bdd4e07-26ba-4dc2-99a8-bdea54bf3d4f」, 「GUID」: 「每個人」, 「嚴重」:空, 「評價」: 「搜索」 ,「rdata」:null,「description」:「search google.com」,「asn_desc」:null,「relatedid」:null,「reporttime」:「2014-04-08T17:34:31Z」,「con fidence「:」50「,」restriction「:」private「,」prefix「:null} {」relatedid_restriction「:null,」purpose「:」mitigation「,」asn「:null,」rir「 「:空,」 CC 「:NULL,」 detecttime 「:」 2014-04-08T17:35:14Z 「 」地址「: 」google.com「, 」alternativeid_restriction「:空, 」ID「:」 1df23bea-AB15 -4410-aab4-d2c538a385fd「,」guid「:」所有人「,」嚴重性「:空,」評估「:」搜索「,」rdata「:空,」描述「:」搜索google.com「,」asn_desc「 :null,「relatedid」:null,「reporttime」:「2014-04-08T17:35:14Z」,「confidence」:「50」,「restriction」:「private」,「prefix」:null}
現在第一個提醒「alert(jqXHR);」返回[對象對象],但第二個「警報(jqXHR.responseText);」返回undefined。
如何在我的JavaScript中檢索響應正文文本?
謝謝
這種反應是不是jsonp。請研究JSONP是什麼。它與你的正常ajax請求非常不同,它根本不是ajax請求。 –