测试文件:11.html
<script language="javascript">
function gg(eid) //get html emement obj by id{
return document.getElementById(eid);
}
function creajaxobj() //cre an ajax object
{
var http_request;
if (window.XMLHttpRequest) // Mozilla, Safari, ...
{
alert('firefox');
http_request = new XMLHttpRequest();
}
else if (window.ActiveXObject) // IE
http_request = new ActiveXObject("Microsoft.XMLHTTP");
return http_request;
}
function qrydata_disp()
{
//alert('kkk');
var oajax;
oajax=creajaxobj();
oajax.onreadystatechange = function()
{
if (oajax.readyState == 4 && oajax.status == 200)
{
var msg; msg=oajax.responseText;
alert(msg);
}
}
var formdata;
//formdata="&sqlstr=" + gg('txt_sql').value;
//alert(formdata);
//
var url="http://192.168.0.3";
oajax.open("POST",url, true); //!!POST true同步 false异步
//oajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
//alert(url);
oajax.send(null);
}
function aa()
{
qrydata_disp();
qrydata_disp();
}
</script>
<input type="button" οnclick="aa();" value="确定">
1、firefox中本地文件11.html测试没有效果,但是放到tomcat下访问没有问题。
2、注意跨域问题,访问html地址开头和ajax访问url地址要相同。