+ -
当前位置:首页 → 问答吧 → Jsp中用ajax取得数据的时候,在form标签中的时候,取到的数据写不到DIV中

Jsp中用ajax取得数据的时候,在form标签中的时候,取到的数据写不到DIV中

时间:2011-01-22

来源:互联网

脚本
var xmlHttpReq;

function createXMLHttpRequest() {
if (xmlHttpReq == null) {
if (window.ActiveXObject) {
xmlHttpReq = new ActiveXObject("MSXML2.XMLHTTP.3.0");
} else {
xmlHttpReq = new XMLHttpRequest();
}
}
}
  function sendReq(Model) {
document.getElementById("SearchStation").value = Station;
createXMLHttpRequest();
var sendTime = new Date();
var url = "servlet/getStationInfo?Model=" + Model;
xmlHttpReq.open("GET", url, true);  
xmlHttpReq.onreadystatechange = showResult;
xmlHttpReq.send();
}
  function showResult() {
if (xmlHttpReq.readyState == 4) {

if (xmlHttpReq.status == 200) {
var result = xmlHttpReq.responseText;

alert(result);
document.getElementById("statInfo").innerHTML = result;

}
}

}

页面
<form ....>
...
<div id="statInfo" style="width:1150px; height:480px; overflow:scroll; font-size:smaller"></div>
...
</form>


注:没有form标签的时候好用

作者: garyfire   发布时间: 2011-01-22

跟form没有关系,请贴出全部的代码

作者: net_lover   发布时间: 2011-01-22

知道原因了,我取回来的数据里面也有form,去掉就正常了

作者: garyfire   发布时间: 2011-01-22