我一直在試圖將json值發佈到API,代碼如下。 也許我應該使用其他方法將json值發送/發佈到API。 Couls有人給我一個提示? 我想能夠發佈一個新的用戶名和密碼到API(用戶名= bruno & password = login),怎麼可能做到這一點? 我可以只使用JavaScript嗎?如何將json值發佈到服務器API?
var url = "http://192.168.8.143/api/v11/login/";
var parameters = "username=bruno&password=login";
http.open("POST", url, true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", parameters .length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {//Handler function for call back on state change.
if(http.readyState == 4) {
alert(http.responseText);
}
}
http.send(parameters);
stackoverflow-user例外:http是undefined,請打一個ajax調用 –
[jQuery發佈JSON]的可能重複(http://stackoverflow.com/questions/5570747/jquery-posting-json) –
@johnSmith好的,你的意思是我應該用ajax調用嗎?你能給我一個提示,告訴我怎麼做? –