运用到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>