Javascript 从php返回提交响应时查询阻止表单

Javascript 从php返回提交响应时查询阻止表单,javascript,php,jquery,Javascript,Php,Jquery,如果用户收到数据库中存在电子邮件的消息,我将尝试停止或禁用提交按钮 我试着在两者之间加一个if,但没有成功。jquery上没有大师 有人说我应该使用e;但是我应该把它放在哪里呢?在任何地方都尝试过,但要么脚本不起作用,要么用户可以注册 也许最好验证php中的所有内容??只是觉得使用验证插件时jQuery更好 有线索吗?谢谢= 有以下脚本: Jquery: $("#email").keyup(function (e){ clearTimeout(x_timer); var

如果用户收到数据库中存在电子邮件的消息,我将尝试停止或禁用提交按钮

我试着在两者之间加一个if,但没有成功。jquery上没有大师

有人说我应该使用e;但是我应该把它放在哪里呢?在任何地方都尝试过,但要么脚本不起作用,要么用户可以注册

也许最好验证php中的所有内容??只是觉得使用验证插件时jQuery更好

有线索吗?谢谢=

有以下脚本:

Jquery:

    $("#email").keyup(function (e){
    clearTimeout(x_timer);
    var e_mail = $(this).val();
            if (e_mail.length > 4) {
        x_timer = setTimeout(function(){
            check_email_ajax(e_mail);
        }, 1000);
    }
}); 

    function check_email_ajax(e_mail){
        $("#email-result").html('<img src="../cms/assets/images/loading.gif" width="20px" height="20px" />');
        $.post('ajax/register.ajax.php', {'email':e_mail}, function(data) {
          $("#email-result").html(data);
        });
    }
PHP:


使用按钮类型=button,您可以完美地使用whitout submit按钮。我想你正在寻找这样的东西:

function check_email_ajax(e_mail){
        $("#email-result").html('<img src="../cms/assets/images/loading.gif" width="20px" height="20px" />');
        $.post('ajax/register.ajax.php', {'email':e_mail}, function(data) {
          $("#email-result").html(data);
          var result= $("i").attr("id")
          if (result==red){
             //If this is the result you stay on the page and user see the red message :)
          }
          if (result==green){
            //If result is green I imagine you want to go where the action in form tag says, so delete action from the form, you can simply redirect where you want:
            url = "your-file.php"
            $(location).attr("href", url)
          }
        });
    }
为图标添加id:


希望它能帮助您。

您可以完美地使用submit按钮,按钮类型=按钮。我想你正在寻找这样的东西:

function check_email_ajax(e_mail){
        $("#email-result").html('<img src="../cms/assets/images/loading.gif" width="20px" height="20px" />');
        $.post('ajax/register.ajax.php', {'email':e_mail}, function(data) {
          $("#email-result").html(data);
          var result= $("i").attr("id")
          if (result==red){
             //If this is the result you stay on the page and user see the red message :)
          }
          if (result==green){
            //If result is green I imagine you want to go where the action in form tag says, so delete action from the form, you can simply redirect where you want:
            url = "your-file.php"
            $(location).attr("href", url)
          }
        });
    }
为图标添加id:


希望它能帮助您。

不确定这是否是最好的解决方案,但它的工作原理应该是这样的

<input id="submit" type="submit" value="Submit">
如果发现电子邮件:

echo '<script> $(document).ready(function() { $("#submit").attr("disabled", "disabled"); }); </script>';
如果未找到电子邮件:

echo '<script> $(document).ready(function() { $("#submit").removeAttr("disabled"); }); </script>'; 

它可以工作:-

不确定这是否是最佳解决方案,但它可以正常工作

<input id="submit" type="submit" value="Submit">
如果发现电子邮件:

echo '<script> $(document).ready(function() { $("#submit").attr("disabled", "disabled"); }); </script>';
如果未找到电子邮件:

echo '<script> $(document).ready(function() { $("#submit").removeAttr("disabled"); }); </script>'; 

工作原理:-

您是否考虑过在电子邮件验证后启用“提交”按钮,否则将其禁用?@XerenNarcy是的,就像我写的那样,一直试图隐藏或显示“提交”按钮,但运气不佳。您是否考虑过在电子邮件验证后启用“提交”按钮,否则将其禁用?@XerenNarcy是,就像我写的,一直试图隐藏提交按钮或显示,但没有运气。感谢帮助=我尝试了你的脚本,但在控制台中我得到一个错误:ReferenceError:找不到变量:绿色,如果出现红旗并且用户电子邮件存在。还试图改变模具;呼应;相反,相同。尝试使用echo;而不是回声;它应该是有效的,因为它只返回带有id的a,而green并不是一个变量,正如您在错误msgeSorry中所说的,因为我的回答延迟,已经离开了几天。但是回到脚本,如果我尝试使用alert来显示结果,不管发生什么,它都会未定义,所以它不会从php文件中获取id?!也尝试了使用此选项,也尝试了不使用echo。感谢帮助=我尝试了您的脚本,但在控制台中我收到一个错误:ReferenceError:如果出现红旗并且存在用户电子邮件,则找不到变量:绿色。还试图改变模具;呼应;相反,相同。尝试使用echo;而不是回声;它应该是有效的,因为它只返回带有id的a,而green并不是一个变量,正如您在错误msgeSorry中所说的,因为我的回答延迟,已经离开了几天。但是回到脚本,如果我尝试使用alert来显示结果,不管发生什么,它都会未定义,所以它不会从php文件中获取id?!也尝试过这个,也没有回声。