Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用ajax检查数据库中的电子邮件时出错_Javascript_Php_Html_Ajax - Fatal编程技术网

Javascript 使用ajax检查数据库中的电子邮件时出错

Javascript 使用ajax检查数据库中的电子邮件时出错,javascript,php,html,ajax,Javascript,Php,Html,Ajax,我已经在这里阅读了几个用户的答案,我的目的是检查电子邮件是否已经在数据库中 我的代码如下 **HTML CODE** <div class="form-group"> <div class="col-sm-12"> <div class="input-group"> <span class="input-group-addon">

我已经在这里阅读了几个用户的答案,我的目的是检查电子邮件是否已经在数据库中

我的代码如下

**HTML CODE**
<div class="form-group">
                  <div class="col-sm-12">
                    <div class="input-group">
                      <span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
                      <input id="fnam" name="firstname" class="profile-input form-control" type="text" placeholder="First Name" autocomplete="off" maxlength="25" required />

                     <!-- <input id="fullname" name="fullname" class="form-control" placeholder="Full Name" required="" type="text">-->
                    </div>
                  </div>
                </div>
            </fieldset>

            <fieldset>
            <!-- Prepended text Last Name-->
                <div class="form-group">
                  <div class="col-sm-12">
                    <div class="input-group">
                      <span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
                      <input id="lastname" name="lastname" class="profile-input form-control" type="text" placeholder="Last Name" autocomplete="off" maxlength="25" required />
             <!-- <input id="fullname" name="fullname" class="form-control" placeholder="Full Name" required="" type="text">-->
                    </div>
                  </div>
                </div>
            </fieldset>

            <fieldset>
                <!-- Prepended text Email-->
                <div class="form-group">
                  <div class="col-sm-12">
                    <div class="input-group">
                      <span class="input-group-addon"><span class="glyphicon glyphicon-envelope"></span></span>
                      <input id="email" name="email"  class="profile-input form-control" type="email" placeholder="Email" autocomplete="off" maxlength="50"  required/>
            <!-- <input id="email" name="email" class="form-control" placeholder="Email" required="" type="text">-->
                    </div>
                  </div>
                </div>
**HTML代码**
JS/AJAX

 function chemail(inputText) {
 var email1 = $("#email").val();
 var x = document.forms["myappForm"]["email"].value;
 var datastring = '$email='+ x; // get data in the form manual



 //var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;  


    var atpos = x.indexOf("@");
    var dotpos = x.lastIndexOf("."); 

// if(inputText.value.match(mailformat)){

  if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length) {

var msgp="Invalid Email. Ex: abc@ggggg.com";
    document.getElementById("msgreturn").style.color= "red";
     document.getElementById("msgreturn").innerHTML = msgp;
      document.getElementById("lem").style.color= "red";
document.myappForm.email.focus();  


return false;  
}  


else  
{  
 document.myappForm.email.focus();  
 var msgp="Email verified";
    document.getElementById("msgreturn").style.color= "green";
     document.getElementById("msgreturn").innerHTML = msgp;
      document.getElementById("lem").style.color= "green";

return true;  


$("span.loading").html("<img src='images/ajax_fb_loader.gif'>");
        $("span.validation").html("");
        var datastring = '&email='+ x;
        $.ajax({
                    type: "POST", // type
                    url: "check_email.php", // request file the 'check_email.php'
                    data: datastring, // post the data
                    success: function(responseText) { // get the response
                        if(responseText == 1) { // if the response is 1
                            $("span.email_val").html("<img src='images/invalid.png'> Email are already exist.");
                            $("span.loading").html("");
                        } else { // else blank response
                            if(responseText == "") {
                                $("span.loading").html("<img src='images/correct.png'> You are registred.");
                                $("span.validation").html("");
                                $("form input[type='text']").val(''); // optional: empty the field after registration
                            }
                        }
                    }
                                    } 
 }
功能模式(输入文本){
var email1=$(“#email”).val();
var x=document.forms[“myappForm”][“email”].value;
var datastring='$email='+x;//获取表单手册中的数据
//var mailformat=/^\w+([\.-]?\w+*@\w+([\.-]?\w+*(\.\w{2,3})+$/;
var atpos=x.indexOf(“@”);
var dotpos=x.lastIndexOf(“.”);
//if(inputText.value.match(mailformat)){

如果(atpos假设您直接复制了代码,那么可以通过检查缩进来发现错误。顺便说一句,我建议您让编辑器将制表符替换为空格,因为制表符可能无法在任何其他系统上正确显示间距(例如!)

其中
x
=
$('#email').val();

值得一提的是,由于您正在将JQuery用于ajax,因此更改如下内容将更加简洁


document.getElementById(“msgreturn”).style.color=“red”
$('msgreturn').css('color','red');
?另外,您
回显'1'
是否找到了一行。您如何判断结果?是否可能有多行带有电子邮件地址?在我的数据库中,目前不可能,我只有3个注册表,var\u dump不检索任何内容,check\u email.php不检索任何内容,但它不显示任何内容4,或控制台上的错误。我已经像你提到的那样更改了。但是,它仍然没有出现在网络检查电子邮件中。phpI不确定应该触发ajax的事件是什么。我没有过多注意错误的括号。我没有看到任何
$(文档)。就绪(函数(){…
这就是事件侦听器的位置。将问题分解为可解决的部分:找出如何触发事件,然后将ajax放入事件中,并找出如何使ajax工作。一次咬一口大象。
<?php require_once("../../php_includes/dbconnect.php"); 

$email = $_POST['x']; 
$query = mysql_query("SELECT 'email' FROM 'members' WHERE 'email' = '$email'"); 
if(mysql_num_rows($query) == 1) {  echo '1'; } else {  echo '1'; } 

?>
function chemail(inputText) {
  var email1 = $("#email").val();
  var x = document.forms["myappForm"]["email"].value;
  var datastring = '$email='+ x; // get data in the form manual



  //var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;  


  var atpos = x.indexOf("@");
  var dotpos = x.lastIndexOf("."); 

  // if(inputText.value.match(mailformat)){

  if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length) {

    var msgp="Invalid Email. Ex: abc@ggggg.com";
    document.getElementById("msgreturn").style.color= "red";
    document.getElementById("msgreturn").innerHTML = msgp;
    document.getElementById("lem").style.color= "red";
    document.myappForm.email.focus();  

    return false;  
  }  

  else

  {  
    document.myappForm.email.focus();  
    var msgp="Email verified";
    document.getElementById("msgreturn").style.color= "green";
    document.getElementById("msgreturn").innerHTML = msgp;
    document.getElementById("lem").style.color= "green";

    return true;  

   // HERE'S THE PROBLEM!!! The following code never gets executed.  Missing parenthesis.

    $("span.loading").html("<img src='images/ajax_fb_loader.gif'>");
    $("span.validation").html("");
    var datastring = '&email='+ x;
    $.ajax({
      type: "POST", // type
      url: "check_email.php", // request file the 'check_email.php'
      data: datastring, // post the data
      success: function(responseText) { // get the response
        if(responseText == 1) { // if the response is 1
          $("span.email_val").html("<img src='images/invalid.png'> Email are already exist.");
          $("span.loading").html("");
        } else { // else blank response
          if(responseText == "") {
            $("span.loading").html("<img src='images/correct.png'> You are registred.");
            $("span.validation").html("");
            $("form input[type='text']").val(''); // optional: empty the field after registration
          }
        }
      }
    } 
  } // <--- this parenthesis is in the wrong place.
var datastring = {email: x};