js ajax实现

function nt_Ajax(type,url,params,callback)
{

if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else //IE5、IE6
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}

xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4)
    {
if(xmlhttp.status==200)
{
if (typeof callback === "function")
{
callback(xmlhttp.responseText);
}
}
    }
}

if(type.toUpperCase() == "POST")
{
xmlhttp.open("POST",url,true); 
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlhttp.send(params);
}
else
{
xmlhttp.open("GET",url,true);
xmlhttp.send(params);
}

}


function CUser()
{
this.id;
this.nicName;
this.password;
this.role;
this.trueName;
this.addr;
this.phone;
this.qq;
this.wechat;
this.email;
this.info;
this.sex;
this.birthday;
}


function AddUserInParams()
{
this.cmd="A";
this.userSct = new CUser();
}


var inParams = new  AddUserInParams();
    inParams.userSct.nicName = $('#tbx_nicName').val(); 
    inParams.userSct.password = $('#tbx_pwd').val();
    inParams.userSct.role = $('#com_role').val();
    inParams.userSct.trueName = $('#tbx_trueName').val();
    inParams.userSct.addr = $('#tbx_addr').val();
    inParams.userSct.phone = $('#tbx_phone').val();
    inParams.userSct.qq = $('#tbx_qq').val();
    inParams.userSct.wechat = $('#tbx_wechat').val();
    inParams.userSct.email = $('#tbx_email').val();
    inParams.userSct.info = $('#tbx_info').val();
    inParams.userSct.sex = $('input:radio[name="rad_sex"]:checked').val();
    inParams.userSct.birthday = $('#tbx_birth').val();
   
    strInparam = JSON.stringify(inParams); 
    nt_Ajax("post","http://localhost/service/User/addUser","usr="+strInparam,ShowResp);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值