繁体   English   中英

无法将检查放入ajax

[英]Cannot put checking in ajax

我有一个带有按钮的启动对话框。 那里的第一个ajax函数有问题。 我想检查从模型和控制器返回的值是0还是1,如果返回的值是1,则停止回调函数将数据发布到数据库。但是,一旦我执行了此检查,则在放入之前它不起作用第一个带有检查功能的ajax函数,一切正常。 现在,我什至无法保存任何数据到数据库。

buttons: {
    success: {
        label: "Save",
        className: "btn-success",
        callback: function() {
            console.log('save');
            console.log($('#re_confirm')[0].checked);
            ...
            ...
            ...

            var check;
                $.ajax({
                url: "<?php echo base_url(); ?>index.php/home/check_occupied",
                type: "post", // To protect sensitive data
                data: {
                        "table_id" : valueid2,
                        "session_id" : table_column_14,
                    //and any other variables you want to pass via POST
                      },
                success:function(response){
                // Handle the response object
                    check=response;
                },
            });

           if(check!=0)
            return;

           $.ajax({
                url : "<?php echo base_url(); ?>index.php/home/update_booking",
                type: "post",
                data: {
                   "table_id" : $('#idtable').val(),
                },
                success: function(response){
                ...
                }
            });
        }
    },
...
,
...
}
});

$ .ajax是异步的

您的代码很容易修复:

$.ajax({
    url: "<?php echo base_url(); ?>index.php/home/check_occupied",
    type: "post", // To protect sensitive data
    data: {
        "table_id": valueid2,
        "session_id": table_column_14,
        //and any other variables you want to pass via POST
    },
    success: function(response) {
        // Handle the response object
        if (response == 0) {
            $.ajax({
                url: "<?php echo base_url(); ?>index.php/home/update_booking",
                type: "post",
                data: {
                    "table_id": $('#idtable').val(),
                },
                success: function(response) {
                    ...
                }
            });
        }
    },
});

暂无
暂无

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

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