繁体   English   中英

如何使我的Ajax从模态向我的php页面发送查询

[英]How can I make my ajax send a query to my php page from a modal

我正在尝试更改数据库中的查询,以查看是否单击了特定按钮,并且他们确认要完成命令。 我有一个按钮想要重置数据库中的所有统计信息。 例如,网站名称,网站座右铭,我希望它们全部重置为我在php文件中拥有的默认值。 当我单击该按钮时,我要创建按钮,这样会弹出一个确认对话框(正在运行)。 我想做到这一点,因此当我单击模式上的“确认重置”时,它将执行我的ajax命令。 我将如何使我的Ajax以模态形式发送到我的php? 我的模态正在工作,但不是ajax。

我的代码:

HTML按钮

<button type="submit" id="button2" name="button2" class="btn btn-inverse" onclick="checkConfirm();">
     <i class="fa fa-refresh"></i>
</button>

JavaScript / AJAX

<script>
function checkConfirm() {
    swal({
            title: "Are you sure?",
            text: "By pressing Yes, you will reset all current database statistics such as money made, purchases made and so on. You will not be able to recover any of the current statistics you have now!",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: '#DD6B55',
            confirmButtonText: 'Yes, reset stats!',
            cancelButtonText: "No, cancel!",
            closeOnConfirm: false,
            closeOnCancel: false
        },
        function(isConfirm) {
            if (isConfirm) {
                swal("Reset!", "Your current statistics have been completely reset! Any statistics you had before, have now been reset to default values.", "success");
                var postResetSend = 1;
                $.ajax({
                    url: "includes/reset_statistics.php",
                    type: "POST",
                    data: { postReset: postResetSend },
                    success: function(data) {
                        window.location.replace("admin_site.php");
                    }
                });
            } else {
                swal("Cancelled", "Your current statistics are safe and have remained the same. Nothing in the database has been altered.", "error");
            }
        });
};
</script>

我的PHP文件

if(!isset($_POST['postReset'])) {
    header('Location: error-pages/index.php');
} else if(isset($_POST['postReset'])) {
    mysqli_query($con, "UPDATE sitesettings set site_name='TeamXerone', team_motto='The Art of Modding', dash_version='17511', site_owner='Ben', user_session_timeout='600', default_user_insert_password='$2y$10$iYg9mVJAUeUMdTyVzYCZuO4QipCg/nnp70VVilBvxKDvr1yyCE9S.', site_url='http://localhost/zackend', paypal_email='admin@hotmail.com', WHERE id='1'");
}

好的,事实证明我的代码是正确的。 我的问题是我不允许我的.htaccess文件访问。

我通过定义文件名进行修复。 例如(我的.htaccess)

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !(reset_statistics)\.php
RewriteRule .* - [R=404,L]

暂无
暂无

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

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