douzong2206 2018-08-14 16:07
浏览 55

Sweetaleart没有在同一页面上发布ajax请求

i have the following which is outputted via a php loop

<?php
    foreach ($decodeMessages as $messages) {
            print  "
         <div class='row clearfix js-sweetalert'>
                            <div class='col-sm-12'>
                            <form action='../Messages/Delete' mehtod='POST'>
                            <div class='card message-page'>
                                <div class='header'>
                                    <h2>
                                       From: " . $messages['Name'] .
                                       "<small>
                                            Email:" . $messages['Email']
                                        ."</small>
                                    </h2>
                                    <ul class='header-dropdown m-r--5'>
                                       <li>
                                            <input type='text' id='mtotal_".$key."' name='mID' value='".$messages['messageTotal']."' >
                                                <button type='button' onclick='showCancelMessage();'  data-key='".$key."' name='".$messages['messageTotal']."' id='submit' class='btn btn-default waves-effect m-r-20 cancel-button' data-type='cancel'><i class='fa fa-trash-o'></i></button>
                                            </li>
                                    </ul>
                                </div>
                                </form>
                                <div class='body'>";
                                        $iv = chr(0x0) . chr(0x0) . chr(0x0);
                                        print openssl_decrypt(base64_decode($messages['Message']), 'aes-256-cbc', $messages['toUser'], OPENSSL_RAW_DATA, $iv);
                               print "</div>
                            </div>
                        </div>
                    </div>
         ";
     }

    ?>

i am using the following to capture and post the following data using

        $(function () {
$('.js-sweetalert button').on('click', function () {
    var type = $(this).data('type');
    if (type === 'cancel') {
        showCancelMessage();
    }
});
});
function showCancelMessage() {
    $('.cancel-button').click(function(){
        var key = $(this).attr('data-key');
        var datastring = $("#mtotal_" + key).val();
    swal({
        title: "Are you sure?",
        text: "You will not be able to recover this imaginary file!",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Delete",
        cancelButtonText: "Cancel",
        closeOnConfirm: false,
        closeOnCancel: false
    }, function (isConfirm) {
        if (!isConfirm) return;
        $.ajax({
            url: "../../Messages/Delete",
            type: "POST",
            data: {
            mID: datastring
        },
        success: function () {
            swal("Done!", "Message succesfully deleted!"+datastring, "success");
        },
        error: function (xhr, ajaxOptions, thrownError) {
            swal("Error deleting!", "Please try again", "error");
        }
    });
});
});
}

content within Messages/Delete:

<?php
    $mID = $_POST['mID'];
    echo "Response: " . $mID;
?>

Now when i use the print_r($_GET['mID']) or print_r($_POST['mID'] they both return empty array's. i'm posting on the same page so i simply added the print_r ontop of the page to see if anything is posted.

if i set a dataType in the ajax it returns with the error "Error Deleting".

So i'm not sure if im missing something with the ajax request, or i am simply not catching it properly using PHP ?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line