异步的时候: JScript code
alert("get");
            this.xmlReq.open(this.method, this.url,this.isAsync);
alert("open");
            this.xmlReq.send(this.data);
在这里我使用了这两个alert,当alert("get");之前不会有(网页错误提示) 
但是当open操作之后,即显示alert("open");之后就会有(网页错误提示) 同步的时候: 
当this.xmlReq.open操作的时候this.isAsync为false即为异步的时候就不会出错后来调适了下,发现每次readystate的值改变的时候,就会出现一次网页报错,郁闷啊!

解决方案 »

  1.   

    readystate 里的函数做了什么事发出来看看
      

  2.   

    this.stateChange = function() {
    var readyState = this.xmlReq.readyState;//得到readyState的值
    //异步处理
    alert("在readyState == 4的外面");
    if (this.xmlReq.status == 200) {
    alert("在this.xmlReq.status == 200的时候");
    if (readyState == 4) {
    var dataS = "<font color='red'>error:The content type is "
    + this.xmlReq.getResponseHeader("content-type")
    + "</font>";//初始化数据
    //对返回类型的判断处理
    //为xml格式的数据
    if (this.type == "xml"
    || this.xmlReq.getResponseHeader("content-type")
    .indexOf("xml") >= 0) {
    dataS = this.xmlReq.responseXML;//得到XML文档对象
    } else
    //为text格式时
    if (this.type == "tex.....这是这个函数中的操作
      

  3.   

    这种ajax操作之前都是这样的啊。。
      

  4.   

    if (readyState == 4) {
        if (this.xmlReq.status == 200) {这样写看看
      

  5.   

    你说的那个this.data吧,就是其在服务器端还没加载完成就在使用它?这个this.data不是通过send函数来加载的呀
      

  6.   


    还有你在readystate==4的时候里面用到的变量因为异步的话是边加载边执行后面的js的,如果你后面js在他没加载完的时候就用到了他,就会出错
      

  7.   

    readystate!=4的时候就有网页报错了。
    readystate==4了以后就可以顺利的得到数据,不报错。
    readystate从0=》4的过程中,变化一次就报错一次,错误都一样的,四次变换四次错误
      

  8.   

    是不是有 this.xmlReq.onreadystatechange = this.stateChange这句代码;
    如果有的话需要注意,this.stateChange定义时this是想指向你定义的Ajax类,但现在触发onreadystatechange的时候,stateChange的指针已经指向了this.xmlReq,需要做一个this指针的绑定Function.prototype.bind = function(bind)
    {
        var fn = this;
        return function()
        {
            return fn.apply(bind);
        }
    }
    this.xmlReq.onreadystatechange = this.stateChange.bind(this);
      

  9.   


    this.xmlReq.onreadystatechange = function() {
    alert("onreadystatechange");
    owner.stateChange.call(owner);//调用stateChange方法,参数为owner
    };回调函数是这样的
      

  10.   

    用同步(false)时是不能用onreadystatechange 的;
    所以你用异步不报错,而用同步就报错。解决办法:判断运行方式,如果是同步跳过onreadystatechange 环节。
      

  11.   

    - -!!这个我当然判断过了this.isAsync这个数就是用来判断的。
      

  12.   

    再说一遍,同步下(this.isAsync为false时),不能使用xmlReq.onreadystatechange调用回调函数,而是要在xmlReq.send(this.data)之后,直接取AJAX的返回值。所以在this.isAsync为false时,你要“屏蔽”有关回调函数的代码
      

  13.   

    我有判断的if(this.isAsync){
    this.xmlReq.onreadystatechange = function() {
    alert("onreadystatechange");
    owner.stateChange.call(owner);//调用stateChange方法,参数为owner
    };
    }
      

  14.   

    this.isAsync为false是同步,不是异步。你到底是同步出错还是异步出错??
      

  15.   

    不好意思我之前打错了,
    this.isAsync为false即为异步改为this.isAsync为false即为同步
    这才是我写的代码,只是发帖的时候写错了,不好意思