php - Sweetalart 不在同一页面上发布 ajax 请求
问题描述
我有以下通过 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'])
orprint_r($_POST['mID']
他们都返回空数组。我在同一页面上发布,所以我只是在页面顶部添加了 print_r 以查看是否发布了任何内容。
如果我dataType
在 ajax 中设置 a,它会返回错误“错误删除”。
所以我不确定我是否错过了 ajax 请求的某些内容,或者我只是没有使用 PHP 正确捕获它?
解决方案
推荐阅读
- python - 需要查找除.dat文件外的文件夹和子文件夹中的文件数
- python - 计算复利
- java - 使用 AWS-SQS 的 JavaCallable-Future 的并发特性
- kubernetes - 使用共享卷在同一 Pod 中的容器之间进行通信
- python - 在符合特定标准的 XYZ 值网格中找到两个节点之间的连续路径
- python - 如何比较两个文件夹、子文件夹和文件的相对路径,并将所有匹配文件的绝对路径传递给函数?
- laravel - Laravel 异步使用 spatie/async
- graphql - 从石墨烯模式中获取查询字符串?
- angular - 带有 ldapjs polyfill 错误的 Angular 12
- android - 访问所有文件 (Android 11)