单击按钮,使用ajax运行php函数

时间:2016-03-02 11:41:16

标签: php jquery ajax forms safari

我想在点击此按钮时运行我的php功能,这在Chrome和Firefox上运行正常,但在Safari上没有,我不知道原因:(请帮帮我......

我的PHP函数是:complete_automate_xml(); 我的按钮是:<button id="btn" onclick="alertWithoutNotice();" class="deletebtn button button-next">Verstuur E-mails</button> 我的代码是:

<script>
    jQuery(document).ready(function($) {
    $('#btn').click(function(){

        $.ajax({
            type: "POST",
            url: '../wp-admin/admin.php?page=spd_xml_importer',
            data: {action: 'call_this'},
            success: function (html) {
                alert(html);
            }

        });
    });
});
</script>
<div class="email-bt">
    <script>function alertWithoutNotice(message) {
            setTimeout(function () {
                alert('E-mails zijn verzonden');
            }, 300);
        }</script>
        <button id="btn" onclick="alertWithoutNotice();" class="deletebtn button button-next">Verstuur E-mails</button>
</div>
<?php
if ($_POST['action'] == 'call_this') {
    complete_automate_xml();
}

1 个答案:

答案 0 :(得分:0)

我的想法更像是这样 - 但我并不是100%确定这是Safari的问题我只是想知道浏览器中是否存在关于调用哪个函数的混淆。

<script>
    jQuery(document).ready(function($) {
    $('#btn').click(function(){
        setTimeout(function() {
            alert('E-mails zijn verzonden');
        }, 300);

        $.ajax({
            type: "POST",
            url: '../wp-admin/admin.php?page=spd_xml_importer',
            data: { action: 'call_this' },
            success: function (html) {
                alert(html);
            }
        });
    });
});
</script>
<div class="email-bt">
        <button id="btn" class="deletebtn button button-next">Verstuur E-mails</button>
</div>