当前位置:编程学习 > C#/ASP.NET >>

AJAX在火孤运行出错。


var xmlhttp;//定义一个变量来存储异步调用对象

function createHttp()//定义一个方法用来实例化xmlhttp异步调用对象
{
   if(window.XMLHttpRequest)//如果当前的浏览器包括XMLHttpRequest对象,则代表它是IE高版本浏览器,或者不是IE浏览器
   {                        //使用XMLHttpRequest
      xmlhttp=new XMLHttpRequest();//实例化异步调用对象
   }
   if(window.ActiveXObject)//代表浏览器是IE的较低版本
   {
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
   }
}

function startHttp(url)//异步传输的方法GET
{
    createHttp();//实例化异步调用对象
    xmlhttp.open("Get",url,true);
    xmlhttp.onreadystatechange=StateCom;//每当xmlhttp对象的readystate属性值发生变化的时候
    //就触发StateCom方法
    xmlhttp.send(null);
    //open方法里第一个参数是get:那么当读取文件时,如果该文件带有参数,则第一个参数使用get
}

function StartHttpP(url,values)//异步传输的方法Post
{
    createHttp();
    xmlhttp.open("Post",url,true);
    xmlhttp.onreadystatechange = StateCom;
    xmlhttp.setRequestHeader( "Content-Type ", "application/x-www-form-urlencoded ");    alert('cc');
    xmlhttp.send(values);
}

function StateCom()//判断是否异步从服务器中读取数据成功
{
    if(xmlhttp.readyState==4)//代表异步调用数据已经完成
    {
        if(xmlhttp.status==200)//代表xmlhttp异步调用对象执行成功
        {
            var xm= xmlhttp.responseText;//从服务器上获得的数据
            $("div").data("Result",xm);//保存数据到DIV
            Receive();//接收数据
        }
    }
}



红色的字体是每次运行到那就出错的。别的浏览器都没问题。 --------------------编程问答-------------------- 来人啊 --------------------编程问答-------------------- 来人啊 --------------------编程问答-------------------- 来人啊
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,