• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
道道前端
daodaoweb
博客园    首页       联系   管理    订阅  订阅

ajax封装

post:function(httphost,sdata,_funsucc,_funerror){

   $.ajax({

       url:httphost,

       type:"POST",

      timeout:500,

      data:sdata,

      success:function(data){  _funsucc(data); },

      error:function(xhr,txtstatus){

           var msg=xhr.responseText;

           if(txtstatus =="timeout"){

                msg="网络连接超时,请重试";

           }else if(txtstatus =="error"){

                if(msg =="") msg="网络连接失败,请查看网络连接";

           }

           _funerror(xhr,txtstatus,msg);

      }

    });

}

 

app.post( config.host, data, function(resp){
//app.loadstop();
console.log("sendnow:rece["+resp+"]");
app.writeTxtFile("/sdcard/sendrece.txt",resp,function(){},function(code){console.log("writeerr:"+code);});
if( resp.substr(0,1) != '{'){
var rdata = {};
rdata['recode']='RETURN SERVER ERROR';
rdata['errormsg'] = resp;
resp = JSON.stringify(rdata);
}

resp = eval( "(" + resp + ")" );
var st = 1;
if( resp.recode=="SUCC") st = 0;
app.insert_sendlog(null, config.app.phonenumber, data['Action'], JSON.stringify(data), JSON.stringify(showdata),null , JSON.stringify(resp), st, 0 );
app.loadstop();
succ( resp );
},function(xhr,txtstatus,errMsg){
app.loadstop();
fail( xhr,txtstatus, errMsg );
}
);

posted @ 2013-10-14 15:06  道道前端  阅读(226)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3