【发布时间】:2013-01-08 00:08:18
【问题描述】:
我有带有电子邮件和密码的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;
};
【问题讨论】:
-
你的请求是异步的,所以没有立即设置有效值。此外,您的代码设计不正确。您使用的是 jquery,那为什么不使用 validate 插件呢?示例alittlecode.com/files/jQuery-Validate-Demo
-
用邮箱和密码注册????
-
并使用 $("EmailChk").html(...);现在你已经有了 jQuery
-
对不起,我不像你那样专家,因为我刚刚开始学习 jquery,但无论如何感谢您的回复
-
您的具体问题是什么。你能解释一下吗?您要查找的输出是什么?
标签: php javascript jquery ajax