简体   繁体   English

为什么此Jquery .post的回调函数不起作用?

[英]Why isn't my callback function for this Jquery .post working?

Here is the code for the jquery: 这是jquery的代码:

<script type="text/javascript"> 
    $(document).ready(function(){
        $('#room').submit(function(){
            $.post('backend/CreateRoom.php', $('#room').serialize() ,function(data) {
                alert(1);
                $('#llama').append(data);
                console.log('working');
            });
        });
        return false;
     }); 
</script>

The function part does not seem to be working. 功能部分似乎无法正常工作。 The PHP code on the backend/CreateRoom.php seems to work fine(the code updates a PHP database) works fine, it just doesnt update the div, or do anything I put in the function. backend / CreateRoom.php上的PHP代码似乎可以正常工作(该代码更新了PHP数据库)可以正常工作,只是不更新​​div或执行我在函数中所做的任何事情。 Help? 救命?

Looks like you are returning false on document ready. 看来您准备好文档时返回false I think you want that on submit. 我认为您希望在提交时提交。

$(document).ready(function(){
    $('#room').submit(function(){
        $.post('backend/CreateRoom.php', $('#room').serialize() ,function(data) {
            alert(1);
            $('#llama').append(data);
            console.log('working');
        });
     return false;
    });

});

or prevent default: 或防止默认:

$(document).ready(function(){
    $('#room').submit(function(event){
        event.preventDefault();
        $.post('backend/CreateRoom.php', $('#room').serialize() ,function(data) {
            alert(1);
            $('#llama').append(data);
            console.log('working');
        });
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM