$.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;}
});
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' => ''
)
)