很实用,方便时可以拿来直接用,很多时候会用到
function httpRequest(url, postData) {
var xmlhttp;try {xmlhttp = new XMLHttpRequest();} catch (trymicrosoft) {try {xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");} catch (othermicrosoft) {try {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");} catch (failed) {xmlhttp = null;}}}
xmlhttp.open("POST", url + '?' + postData, false);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlhttp.send(null);return xmlhttp.responseText;
}
我目前主要是在ext中用到,将返的数据直接Ext.decode()转成对象,然后就可以访问对象的数据了。