你的这个JS写得有点……不太规范在你上边随便改的,你看能行了不
var xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open("Post", "?ProvinceID=2", false);
xmlHttp.send(null);document.getElementById("txtContent").innerHTML=result;
document.all.divmoment.style.display="none";function handleStateChange() {
if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
document.getElementById("txtContent").innerHTML=xmlHttp.responseText;
document.all.divmoment.style.display="none";
}
}
else {
document.all.divmoment.style.display='block';
}
}
var xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open("Post", "?ProvinceID=2", false);
xmlHttp.send(null);document.getElementById("txtContent").innerHTML=result;
document.all.divmoment.style.display="none";function handleStateChange() {
if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
document.getElementById("txtContent").innerHTML=xmlHttp.responseText;
document.all.divmoment.style.display="none";
}
}
else {
document.all.divmoment.style.display='block';
}
}
你这里用false,你是想让他同步,不是异步吗?
function call()
{
xmlHttp=new ActiveXObject("MSXML2.XMLHTTP");
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open("Post", "?ProvinceID=2", false);
xmlHttp.send();
}
function handleStateChange()
{
if(xmlHttp.readyState == 4)
{
if(xmlHttp.status == 200)
{
document.getElementById("txtContent").innerHTML=xmlHttp.responseText;
document.all.divmoment.style.display="none";
}
}
else
{
document.all.divmoment.style.display='block';
}
}
提示缺少对象
if(window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}
有多少方法可以用,偏偏喜欢个all
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script>
function customers(id,name,sex,age,address){
this.id=id;
this.name=name;
this.sex=sex;
this.age=age;
this.address=address;
}
function customer(){
var cutomer=new customers(1,'san','男',25,'深圳市');
var fields="";
for(var i in cutomer){
var property=cutomer[i];
fields+=i+" = "+property+"\n";
}
alert(fields);
}
var xmlHttp;
function createXMLHttpRequest() {
if(window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}function call()
{
createXMLHttpRequest();
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open("Post", "test.txt", true);
xmlHttp.send();
}
function handleStateChange()
{
if(xmlHttp.readyState == 4)
{
if(xmlHttp.status == 0)
{
for(var i=0;i<9999999;i++){
//document.getElementById("number").innerHTML=i;
if(i==9999998){
//alert(i);
document.getElementById("txtContent").innerHTML=xmlHttp.responseText;
document.all.divmoment.style.display="none";
}
}
}
}
else
{
document.all.divmoment.style.display='block';
}
}</script>
</HEAD><BODY onload="call();">
<div id="divmoment" style="display:none">请稍候!</div>
<div id="txtContent" style="display:blank"></div>
<div id="number" style="display:blank"></div>
<br><br><br><br><br><br><br><br><br>
<input type="button" name="test" value="TEST" onclick="javascript:customer();">
</BODY>
</HTML>