Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/54.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 我们如何使用AJAX发送/获取http头信息?_Ruby On Rails_Ajax_Http - Fatal编程技术网

Ruby on rails 我们如何使用AJAX发送/获取http头信息?

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

有没有办法通过AJAX发送/获取http头(比如,内容类型…)?。那么,请解释一下,我们将通过在AJAX中传递http头来归档什么,在哪里使用这种技术

谢谢

我不是专家

但是,您应该查看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();
}
我不是专家

但是,您应该查看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]: