我正在尝试对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);