我正在尝试对 Flipkart 搜索 api 执行简单的 GET 请求。
baseurl= 'https://affiliate-api.flipkart.net/affiliate/search/json?';
params={
query:name,
resultCount:5
};
var xhr=new XMLHttpRequest();
xhr.open('GET',baseurl+$.param(params),false);
xhr.setRequestHeader("Fk-Affiliate-Id","myidhere");
xhr.setRequestHeader("Fk-Affiliate-Token","mytokenhere");
xhr.send();
使用异步 XMLHttpRequest() 后,出现以下错误:
var xhr = new XMLHttpRequest();
xhr.open("GET", baseurl+$.param(params), true);
xhr.onload = function (e) {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
console.log("gowofee",xhr.responseText);
} else {
console.error("gowofee",xhr.statusText);
}
}
};
xhr.onerror = function (e) {
console.error("gowofee",xhr.statusText);
};
xhr.setRequestHeader("Fk-Affiliate-Id","myid");
xhr.setRequestHeader("Fk-Affiliate-Token","mytoken");
xhr.send(null);