-1

如果我执行以下代码,那么我启用了 firebug。在提交表单时在 firebug 中,在控制台中“post to login_submit.php”显示为红色。我也没有得到任何响应。

<!DOCTYPE html>
    <html>
    <head>
    <title>Login page</title>
    <script type="text/javascript" src="js/jquery.min.js">
    </script>
    <script type="text/javascript" src="js/scripts.js">
    </script>

    <script type='text/javascript'>

    function submit_login_form()
    {
    var action = "login_submit.php";

        $.ajax(
          {
          url: 'login_submit.php',
          type: 'POST',
          data: $('#login').serialize(),
          success: function(data_in) 
            {
              alert(data_in);
              if (data_in !== null && !isEmpty(data_in) && (data_in).indexOf('VALIDATION_ERROR') !== -1)
              {
                var value = data_in.substr(data_in.indexOf('VALIDATION_ERROR'), data_in.indexOf('|#END#'));
                var array_str = value.split('|');
                var id_val = "#id_" + array_str[1].trim();
                show_error(id_val, array_str[2]);
              } else 
              {
                window.location.replace('jb_organization_regn_confirm.html');
              }
            }
          }
        );
        return false;
    }
    </script>
    </head>
    <body>
    <form action="login_submit.php" id="login">
    <h1>LOGIN</h1>
    Email<input value="" name="user_email" id="user_login"><br>
    Password<input value="" name="pwd" type="password" id="pwd_login"><br>
    <input type="checkbox" name="remember_me">Stay Signed In<br>
    <input type="submit" value="login" onclick="submit_login_form()">  
    </form>
    </body>
    </html>

下面是我的 login_submit.php

<?php require 'db.php'; ?>
<?php require 'shopping_user_class.php'; ?>
<?php 
$error_op = " START ";
$obj_shopping_login = new user;
//$obj_shopping_login->shopping_user_name = "";
$obj_shopping_login->shopping_user_pwd = "";
$obj_shopping_login->shopping_user_email = "";
$obj_shopping_login->remember_me = "";
function Collect_all_form_variables() {
    global $obj_shopping_login;
    global $error_op;

    try {

        $obj_shopping_login->shopping_user_email = $_POST["user_email"];
        $obj_shopping_login->shopping_user_pwd = $_POST["pwd"];

        if (isset($_POST['remember_me']) &&
                $_POST['remember_me'] == 'yes') {
            $obj_shopping_login->remember_me = 'yes';
        } else {
            $obj_shopping_login->remember_me = 'no';
        }
    } catch (Exception $e) {
        echo 'Error: ' . $e->getMessage();
        $error_op = 'Collect_all_form_variables' . $error_op . $e->getMessage();
    }

}
function check_useremail_and_password($current_user_email,$current_user_pwd) {
    global $error_op;


    try {
        global $pdo;



        $sth = $pdo->prepare("SELECT * from photostudio.user WHERE  UPPER(email) =  UPPER(:current_user_email) AND pwd=:current_user_pwd");

// Execute the query, replacing the placeholders with their true value
        $sth->execute(array(
            ':current_user_email' => trim($current_user_email),
            ':current_user_pwd'=>current_user_pwd
        ));

        if ($sth->rowCount() > 0) {

            return true;
        }

        return false;
    } catch (PDOException $e) {
        echo 'Error: ' . $e->getMessage();
        $error_op = 'check_useremail_and_password ' . $error_op . $e->getMessage();
    }

    return true;
}
function validate_form_stage1() {

//alert("please");
    $required = array('user_email', 'pwd');

// Loop over field names, make sure each one exists and is not empty
    $error = false;
    foreach ($required as $field) {
        if (empty($_POST[$field])) {
            $error = true;
            break;
        }
    }

    if ($error) {
        return "VALIDATION_ERROR|" . $field . "|Value is Required|#END#";
    } else {
        return "SUCCESS";
    }
} 
function process_request() {


    global $obj_shopping_login;

    global $error_op;

    $all_values_are_present = validate_form_stage1();

    if (substr($all_values_are_present, 0, 16) === "VALIDATION_ERROR") {


        echo $all_values_are_present;
        return false;
    }

    Collect_all_form_variables();
    if (check_useremail_and_password() == true) {

        echo "Success" . $error_op;


    } else {

        echo "Failed" . $error_op;
    }
}
?>
4

6 回答 6

1

添加var $ = jQuery您的脚本顶部,例如..

<script type='text/javascript'>
   var $ = jQuery;
   // your functions here...
</script>

或者

$(document).ready(function() {
  // your functions here...
});

推荐 :

在结束<body>标签之前添加你的脚本,比如......

<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Your Website</title>
</head>
<body>
    <header>
    </header>

    <section>
    </section>

    <aside>
    </aside>

    <footer>
    </footer>


    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script>window.jQuery || document.write('your_local_here/jquery.js"><\/script>')</script>
    <script src="custom.js"></script>
    <script>
        // or here
    </script>
</body>
</html>
于 2013-10-25T13:23:22.457 回答
0

您需要将代码包装到

$(function() {
  // your code here...
});

这将确保您的代码在您访问的所有 DOM 元素已经可用时按预期工作。至于 jQuery 本身,请尝试将本地 jQuery 包含替换为

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

看看是否有帮助。如果是这样,则您的本地文件未正确包含 - 可能是错误的文件夹/子文件夹。

于 2013-10-25T13:21:22.563 回答
0

每当您看到$ is not defined没有加载 jquery 的意思时。添加这个:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>

还请记住,此路径必须位于所有其他 jquery 文件或脚本之上。

于 2013-10-25T13:21:48.033 回答
0

请检查您的 jquery 文件路径 在“就绪事件”中写入您的脚本

$(document).ready(function(){
   //Some javascript code
});
于 2013-10-25T13:21:52.630 回答
0

如果我不得不猜测,我会说这个文件在一个子文件夹中。

确保使用相对于域根目录而不是当前文件的路径包含脚本:

<script src="/js/jquery.min.js"></script>
<script src="/js/scripts.js"></script>

这将确保可以找到您的脚本,无论您在站点的哪个位置。

于 2013-10-25T13:20:05.170 回答
0

如果 jQuery 加载正确,原因可能在 $-definition 中。尝试以这种方式覆盖它:

jQuery(document).ready(function($){
   //Now you can use $
});
于 2013-10-25T13:26:17.900 回答