我有问题。我尝试向 Web 服务器 XBMC 发送 JSON 请求。我可以在 Wireshark 中看到 POST 请求已正确发送,响应由 Web 服务器发送,但在 Javascript 中,我无法将 JSON 数据显示在警报中。
var xhr_object = null;
if(window.XMLHttpRequest) // Firefox
xhr_object = new XMLHttpRequest();
else if(window.ActiveXObject) // Internet Explorer
xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
else { // XMLHttpRequest non supporté par le navigateur
alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
return;
}
xhr_object.open("POST", "http://"+add+":9000/jsonrpc", false);
xhr_object.onreadystatechange = function() {
if(xhr_object.readyState == 4)
var json = xhr_object.responseText;
alert(xhr_object.responseType)
alert("("+json+")");
}
xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
var data = '{"jsonrpc": "2.0", "method": "Input.Up", "id": "1"}';
xhr_object.send(data);