您的位置:首页 > 理论基础 > 计算机网络

关于Ajax异步请求XmlHttp

2015-05-29 14:57 781 查看
运用到Ajax异步请求XmlHttp。

<span style="font-size:14px;">    var xmlHttp
function createXMLHttp(){
if (window.XMLHttpRequest){                     // 创建XMLHttpRequest核心对象
xmlHttp = new XMLHttpRequest()
}else {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
// 使用IE内核的浏览器
}
}  </span>
创建异步请求。

<span style="font-size:14px;">function initArea(){
createXMLHttp();    //
// 设置请求
xmlHttp.open("POST","${webRoot}/....);
// 设置完请求后调用处理回调函数  </span>
<span style="font-size:14px;">    xmlHttp.send("field=field_value");
xmlHttp.send(null);</span>
<span style="font-size:14px;">    //设置返回参数时调用方法
xmlHttp.onreadystatechange = function(){callback()};
}</span>
<span style="font-size:14px;">
</span>
<span style="font-size:14px;">//请求返回参数值</span>
<pre name="code" class="javascript"><span style="font-size:14px;">function callback(obj_value_id) {
var test;
if(xmlHttp.readyState == 4) {
text = xmlHttp.responseText;
//业务处理
}
}
}</span>



<span style="font-size:14px;">
</span>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: