我有以下内容通过php循环输出
<?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>
";
}
?>
我正在使用以下内容来捕获并使用
发布以下数据 $(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");
}
});
});
});
}
Messages/Delete
中的内容:
<?php
$mID = $_POST['mID'];
echo "Response: " . $mID;
?>
现在,当我使用print_r($_GET['mID'])
或print_r($_POST['mID']
时,它们都返回空数组。我在同一页面上发布,因此我只是在页面顶部添加了print_r,以查看是否发布了任何内容。
如果我在ajax中设置了dataType
,则会返回错误“错误删除”。
所以我不确定我是否在ajax请求中缺少某些内容,或者我只是没有使用PHP正确地捕获它?