weixin_33698823 2016-04-26 06:55 采纳率: 0%
浏览 97

$ .post似乎不起作用

There are a couple of alert() calls in the jQuery which are showing up, but the alert inside the $.post does not seems to respond. I already tested the PHP code and it works fine. I think it is my path, but I already check them before.

<form id="login-form" method="post" class="form-inline" target="_top">
    <input type="text" tabindex="2"  id="username" placeholder="Username" name="email" class="inputtext">
    <input type="password" tabindex="3" id="userpass" placeholder="Password" name="pass" class="inputtext">
    <button tabindex="4" id="loginButton">Login</button>
</form>
$(document).ready(function(e) {
    $('#loginButton').click(function(e) {
        alert("start function");
        $.post('../php/login.php', {
            'username': $('#username').val(),
            'userpass': $('#userpass').val()
        }, function(data){
            alert(data);
        });
        alert("end function");
    });
});
<?php    
    require('config.php');

    $queryStmt = 'SELECT user_first, user_last FROM users WHERE user_name=:sqlIdName AND user_password=:sqlPass';
    $queryPrepare = $dba_connect->prepare($queryStmt);
    $queryPrepare->execute(array(':sqlIdName'=>$_POST['username'],':sqlPass'=>md5($_POST['userpass'])));
    $queryResult = $queryPrepare->fetch(PDO::FETCH_ASSOC);
    $queryPrepare->closeCursor();

    var_dump($queryResult);

    if ($queryResult == false)
        return false;
    else 
        return true;  
?>

My file structure is this:

File Structure

  • 写回答

3条回答 默认 最新

  • weixin_33721427 2016-04-26 06:59
    关注

    Try this:

    $(document).ready(function(e) {
        $('#loginButton').click(function(e) {
            $.post('../php/login.php', {
                functions: 'userLogin',
                username: $('#username').val(),                    
                userpass: $('#userpass').val()
            }).done(function( data ) {
                alert("Data Loaded: " + data);
            });
        });
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵