Ajax请求没有连接

时间:2016-06-23 12:45:50

标签: php jquery ajax

enter image description here

$("#email").keyup(function() {
              var vall = $(this).val();

              if(vall == "") {
                  $("#emailerror").html("Email should not be empty");
                  email = "";
              } 
               else {
                  $.ajax({
                      type: "post",
                      url: "script.php",
                      data: "email=" +vall,
                      success: function(msg) {
                         $("#emailerror").html(msg); 
                      }
                  });
              }
          });

         <?php
      include 'includes/db.php';

      if(isset($_POST['email'])) {
          $email = $_POST['email'];
          echo $email;
      }
      ?>

这是我的两个不同的文件,一个是ajax请求,另一个是php脚本,我试图通过ajax通过电子邮件验证它是否已经存在于数据库中,但是在控制台中存在某种错误,如下面的屏幕截图中所示任何建议我是什么问题

enter image description here

2 个答案:

答案 0 :(得分:1)

问题在于MAX(TERM_END_DATE)文件的网址尝试这样做。首先,你应该有一个BASE_URL或SITE_URL,如

script.php

然后在jQuery中附加到这个URL,这样就可以生成像

这样的完整路径
define('SITE_URL', 'http://www.example.com');

这将调用script.php文件(根据您的设置调整$("#email").keyup(function() { var vall = $(this).val(); if(vall == "") { $("#emailerror").html("Email should not be empty"); email = ""; } else { $.ajax({ type: "post", url: "<?php echo SITE_URL;?>/script.php", data: "email=" +vall, success: function(msg) { $("#emailerror").html(msg); } }); } }); 文件路径的路径。

答案 1 :(得分:-1)

您可以尝试以下内容。

$.ajax({
 type: "POST",
 url: "script.php",
 data: {email: vall},
 success: function(msg) {
   $("#emailerror").html(msg); 
 }
相关问题