面对jQuery与ajax的问题

时间:2013-01-24 09:28:12

标签: php javascript jquery ajax

我有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 = "" ;

               }

如果我在这里放置警报消息然后没有问题或向下返回任何地方返回有效但如果我删除警报消息然后查询插入数据到数据库......

               return Valid;

        };

1 个答案:

答案 0 :(得分:2)

你必须更多地了解 jquery ajax 来自ajax的响应应该是html形式。您可以在alert区块success取悦它,然后您就可以了解问题 试试吧。

else
{
   $.ajax({
             url  : 'RegCheck.php',
             type : 'POST',
             data : {User: address},
                    success : function(result){
                       alert(result);
                       if(result != "No")
                       {
                         document.getElementById("EmailChk").innerHTML = result;                      Valid = false;
                       }
                    }

               });              



}