我有带有电子邮件和密码的registration.php页面,它在提交时调用了一个函数,即
the function ChkVal() is written in comman.js file i.e
function ChkVal()
{
var Valid = true;
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var address = document.getElementById("Email").value;
if(reg.test(address) == false)
{
////somecode to check if it is valid email id or not
}
else
{
this is the section where i have the problem
$(function() {
$.ajax({
url : 'RegCheck.php',
type : 'POST',
data : 'User=' + address,
success : function(result){
if(result != "No")
{
document.getElementById("EmailChk").innerHTML = result;
///the result return from RegCheck.php will be Either already exist or No
Valid = false;
}
}
});
});
document.getElementById("MailMand").innerHTML = "" ;
}
如果我在此处放置警报消息,则在返回 Valid 之前没有问题或向下任何位置,但是如果我删除警报消息,则查询将数据插入数据库...
return Valid;
};