zoukankan      html  css  js  c++  java
  • appcan封装好的ajax,解决onDATA覆盖问题

    ajax.js

    window.AJAX = {  
    callBack : {},index : 1,
    get : function(url,succCall,errCall,timeout,getid){
      //var id = this.index++;
      var id=getid;
      //alert(id);
      this.callBack[id] = [succCall,errCall];
      uexXmlHttpMgr.open(id,'get',url,(timeout||0));
      this._send(id);
    },
    post : function(url,data,succCall,errCall,timeout,getid){
      //var id = this.index++;
      var id=getid;
      this.callBack[id] = [succCall,errCall];
      uexXmlHttpMgr.open(id,'post',url,(timeout||0));
      if(data){
       for(var k in data){
        uexXmlHttpMgr.setPostData(id,0,k,data[k]);
       }
      }
      this._send(id);
    },
    _send : function(id){
      uexXmlHttpMgr.onData = this.onData;
      uexXmlHttpMgr.send(id);
      //uexXmlHttpMgr.close(id);
    },
    onData : function(inOpCode,inStatus,inResult){
      var that=AJAX,callBack = that.callBack[inOpCode]||[];
      if(inStatus==-1){
       callBack[1] && callBack[1]();
       delete that.callBack[inOpCode];
      }else if(inStatus==1){
       callBack[0] && callBack[0](inResult); 
       delete that.callBack[inOpCode];
      }
      
    }
    };

    调用ajax

    //get方法
    AJAX.get(url,function(res){
            alert(res)
        },function(){
            alert('返回失败');    
        });
    
    //post方法
    
    
    

    AJAX.post(url,{
        'sinaid':'1910738505',
        'sinaname':'我在这里',
        'data':'{"companyid":"1"}',
        'token':token
      },function(res){
        alert(res);
          res= eval('(' + res + ')');;
          for( var x in res.data){
          for(var j in res.data[x]){
            alert(res.data[x][j])
          }
        }
      },function(){
      alert('返回失败');
    });

     
  • 相关阅读:
    让思考成为一种习惯:今年,我大四了
    asp.net core源码飘香:Logging组件
    asp.net core源码飘香:Options组件
    asp.net core源码飘香:Configuration组件
    asp.net core源码飘香:从Hosting开始
    webpack code split实现原理
    css specificity
    todo:read
    React Render Props 模式
    recompose mapProps 函数指南
  • 原文地址:https://www.cnblogs.com/xiongwei89/p/3141974.html
Copyright © 2011-2022 走看看