weixin_33698043 2017-11-15 10:54 采纳率: 0%
浏览 21

AJAX POST数据未发送

On button click, i want to post the contents of the email text box. When i click the login button nothing happens.

My File dir:

Model/ <-- configuration.php is inside Model dir.

View/

Controller/

index.php <-- calls the header, body, and footer php classes that are in the view dir

                    <!-- Modal body -->
                <div class="modal-body" style="padding:40px 50px;">
                    <form>
                        <div class="form-group">
                            <label for="usrname"><span class="glyphicon glyphicon-user"></span> Username</label>
                            <input type="text" class="form-control" name="email" id="email" placeholder="Enter email">
                        </div>
                        <div class="form-group">
                            <label for="psw"><span class="glyphicon glyphicon-eye-open"></span> Password</label>
                            <input type="text" class="form-control" id="password" placeholder="Enter password">
                        </div>
                        <div class="checkbox">
                            <label><input type="checkbox" value="" checked>Remember me</label>
                        </div>
                        <button type="button" name="loginButton" id="loginButton" name="loginButton" class="btn btn-success btn-block">Login</button>
                    </form>
                </div>

                <!-- Modal footer -->
                <div class="modal-footer">
                    <p>Not a member? <a href="View/registration.php">Sign Up</a></p>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(document).ready(function() {
        $("#loginButton").click(function() {
            $.ajax({
                type: "POST",
                url: "Model/configuration.php?action=login",
                data: "email=" + $("#email").val(),
                success: function (result) {
                    alert("result");
                }
            })
        })
    })
</script>

PHP file

<?php

if($_GET['action'] == "login") {
    print_r($_POST);
}

?>
  • 写回答

3条回答 默认 最新

  • weixin_33734785 2017-11-15 11:03
    关注
    $("#loginButton").click(function() {
                $.ajax({
                    type: "POST",
                    url: "Model/configuration.php?action=login",
                    data: {email:$("#email").val()},
                    success: function (result) {
                        alert("result");
                    }
                })
            })
    
    评论
  • weixin_33670786 2017-11-15 11:06
    关注

    You should serialize your form and pass to data.

    data: $("#FormId").serialize()
    

    See also https://api.jquery.com/serialize/

    评论
  • weixin_33691817 2017-11-15 11:08
    关注

    The problem seems to be that your if condition had an extra parentheses.

    Try this:

    <?php
    
    if($_GET['action'] == "login") {
        print_r($_POST);
    }
    
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 oled显示有问题,初始化后应该啥也不显示,但却亮了一大片
  • ¥15 【通信原理】为什么传信率不变?频带利用率为啥没有二倍
  • ¥15 CANOPEN SDO
  • ¥15 r语言数据集循环获取问题
  • ¥30 求佬们帮助,总是出bug,求佬们解决一下bug
  • ¥15 后端Java转换字符串传给前端,前端如何解析呢?
  • ¥15 psychopy(python为基础的)中引入cmd
  • ¥15 不知道怎么去做关于前端电子请柬
  • ¥15 Ubuntu22.04打开是tty界面。提示OOM
  • ¥15 存储过程或函数中的结果集类型变量如何使用。