jquery Ajax用法和底层ajax实现

	$.ajax({
		url: '../../services/users_serivce.php',
		type: 'POST',
		async:false,//设置为同步
		data:{
        	method: "is_exist",
        	where: where,
    	},
		dataType: 'html',
		timeout: 1000,	
		error: function(){alert('Error loading PHP document');},
		success: function(txt){result=txt;}
	});


jQuery $.post $.ajax用法


jQuery - AJAX


function Ajax(url){
    var m_xmlReq = null;
    if (window.ActiveXObject) {
        try {
            m_xmlReq = new ActiveXObject('Msxml2.XMLHTTP');
        } 
        catch (e) {
            try {
                m_xmlReq = new ActiveXObject('Microsoft.XMLHTTP');
            } 
            catch (e) {
            }
        }
    }
    else if (window.XMLHttpRequest) {
            m_xmlReq = new XMLHttpRequest();
        }
    
    this.post = function(d){
        if (!m_xmlReq) 
            return;
        m_xmlReq.open('POST', url, false);
        m_xmlReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=utf-8');
        m_xmlReq.send(d);
        return (m_xmlReq.responseText);
    }
}

调用如下

var data = {
    "account_email": txtRegName,
    "account_email_code": code,
    "account_email_status": 0,
    "password": hex_md5($F("txtPassword"))
};
var email_register_ajax = new Ajax("../../services/users.serivce.php");
var postData = "method=insert"
	+"&data[account_email]=" + data.account_email
	+"&data[account_email_code]=" + data.account_email_code
	+"&data[account_email_status]=" + data.account_email_status
	+"&data[password]=" + data.password;
if (email_register_ajax.post(postData)) {
    //邮箱数据插入成功,执行邮箱发送动作
    var email_send_ajax = new Ajax("../../services/mail.service.php");
    postData = 'email=' + txtRegName + '&code=' + code;
    if (email_send_ajax.post(postData)) {
        //邮件发送成功,跳转
        location.href = '../../account/regemailok.php?email=' + txtRegName;
    }
}

php端解析的形式为

array (
		'method' => 'insert',
		'data' => array (
				'account_email' => '',
				'account_email_code' => '',
				'account_email_status' => '',
				'password' => '' 
		) 
)


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值