2011-03-31 67 views

回答

1

我不是专家,

但是你应该看看AJAX对象XmlHttpHeaderthe wikipedia article here

编辑:引述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(); 
} 
+0

感谢@stephane。我已经知道XmlHttpHeader。但是,我需要非常简短的信息和关于这个问题的例子? – 2011-03-31 13:50:23

+0

我认为[www.w36.org参考文献] [1]的介绍非常简短,不是吗? [1]:http://www.w3.org/TR/XMLHttpRequest/#introduction – 2011-03-31 13:58:35