Ruby on rails 我们如何使用AJAX发送/获取http头信息?
有没有办法通过AJAX发送/获取http头(比如,内容类型…)?。那么,请解释一下,我们将通过在AJAX中传递http头来归档什么,在哪里使用这种技术 谢谢我不是专家 但是,您应该查看AJAX对象,并对其进行分析 编辑:引用www.w3.org参考:Ruby on rails 我们如何使用AJAX发送/获取http头信息?,ruby-on-rails,ajax,http,Ruby On Rails,Ajax,Http,有没有办法通过AJAX发送/获取http头(比如,内容类型…)?。那么,请解释一下,我们将通过在AJAX中传递http头来归档什么,在哪里使用这种技术 谢谢我不是专家 但是,您应该查看AJAX对象,并对其进行分析 编辑:引用www.w3.org参考: function test(data) { // taking care of data } function handler() { if(this.readyState == 4 && this.status == 200
function test(data) {
// taking care of data
}
function handler() {
if(this.readyState == 4 && this.status == 200) {
// so far so good
if(this.responseXML != null && this.responseXML.getElementById('test').firstChild.data)
// success!
test(this.responseXML.getElementById('test').firstChild.data);
else
test(null);
} else if (this.readyState == 4 && this.status != 200) {
// fetched the wrong page or network error...
test(null);
}
}
var client = new XMLHttpRequest();
client.onreadystatechange = handler;
client.open("GET", "unicorn.xml");
client.send();
如果您只想将消息记录到服务器:
function log(message) {
var client = new XMLHttpRequest();
client.open("POST", "/log");
client.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
client.send(message);
}
function fetchStatus(address) {
var client = new XMLHttpRequest();
client.onreadystatechange = function() {
// in case of network errors this might not give reliable results
if(this.readyState == 4)
returnStatus(this.status);
}
client.open("HEAD", address);
client.send();
}
或者,如果要检查服务器上文档的状态:
function log(message) {
var client = new XMLHttpRequest();
client.open("POST", "/log");
client.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
client.send(message);
}
function fetchStatus(address) {
var client = new XMLHttpRequest();
client.onreadystatechange = function() {
// in case of network errors this might not give reliable results
if(this.readyState == 4)
returnStatus(this.status);
}
client.open("HEAD", address);
client.send();
}
我不是专家
但是,您应该查看AJAX对象,并对其进行分析
编辑:引用www.w3.org参考:
function test(data) {
// taking care of data
}
function handler() {
if(this.readyState == 4 && this.status == 200) {
// so far so good
if(this.responseXML != null && this.responseXML.getElementById('test').firstChild.data)
// success!
test(this.responseXML.getElementById('test').firstChild.data);
else
test(null);
} else if (this.readyState == 4 && this.status != 200) {
// fetched the wrong page or network error...
test(null);
}
}
var client = new XMLHttpRequest();
client.onreadystatechange = handler;
client.open("GET", "unicorn.xml");
client.send();
如果您只想将消息记录到服务器:
function log(message) {
var client = new XMLHttpRequest();
client.open("POST", "/log");
client.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
client.send(message);
}
function fetchStatus(address) {
var client = new XMLHttpRequest();
client.onreadystatechange = function() {
// in case of network errors this might not give reliable results
if(this.readyState == 4)
returnStatus(this.status);
}
client.open("HEAD", address);
client.send();
}
或者,如果要检查服务器上文档的状态:
function log(message) {
var client = new XMLHttpRequest();
client.open("POST", "/log");
client.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
client.send(message);
}
function fetchStatus(address) {
var client = new XMLHttpRequest();
client.onreadystatechange = function() {
// in case of network errors this might not give reliable results
if(this.readyState == 4)
returnStatus(this.status);
}
client.open("HEAD", address);
client.send();
}
谢谢@stephane。我已经知道XmlHttpHeader。但是我需要关于这个问题的非常简短的信息和例子。我认为[www.w36.org参考][1]的介绍非常简短,不是吗?[1] :谢谢@stephane。我已经知道XmlHttpHeader。但是我需要关于这个问题的非常简短的信息和例子。我认为[www.w36.org参考][1]的介绍非常简短,不是吗?[1]: