【发布时间】:2015-07-07 00:33:31
【问题描述】:
我无法弄清楚为什么我的代码不起作用。我要做的是向一个在线 API 发送一个 POST 请求,该 API 也会返回 JSON 数据。在它说“正在搜索帐户数据...”之后,该代码似乎没有执行很多其他操作。
函数请求板信息(){
var xmlhttp = new XMLHttpRequest();
//BoardInfoUrl = getBoardInfoUrl();
BoardInfoURL = "https://meshech.leankit.com/kanban/api/board/2847596743/searchcards";
var parameters = {
"searchOptions":{
"SearchTerm": "",
"SearchInBoard": true,
}
};
xmlhttp.open("POST", BoardInfoUrl, true);
xmlhttp.setRequestHeader("Content-type", "application/json");
document.getElementById("search").innerHTML = "Searching for account data...";
xmlhttp.onreadystatechange = function () {
document.getElementById("search").innerHTML = "Processing next request...";
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
//define what to retrieve here
document.getElementById("search").innerHTML = "jsonData found!";
jsonData = xmlhttp.responseText;
createFile();//creates a text file
//the variable below is the parameters for the POST function in JSON.
}
}
xmlhttp.send(JSON.stringify(parameters));
}
我确定它没有进入 onreadystatechange 函数,但我不知道为什么。任何帮助将不胜感激。 提前致谢。
编辑:好的,所以我将代码更改为在 setrequestheader 之前打开。但现在它在打开时停止。
【问题讨论】:
-
浏览器的调试控制台说什么?
标签: javascript json post