初始ajax事件将唯一的数字ID保存到以下输入标记的value属性中:
<input class="avatar-id" id="avatar-id" name="id" value="">
我想使用jquery ajax将此值发送到名为delete_list.php的php脚本。我想我在这里错误地使用jquery ajax DATA设置来拉出值:
$("#dformclose").click(function() {
if (confirm("Are you sure you want to cancel this? Your image and any information in this form will be deleted")) {
var id = id;
$.ajax({
type: "POST",
dataType:"html",
url: "delete_list.php",
data: "#avatar-id.attr(value.id)",
success: function(response) {
location.reload(true);
}
});
}
else
{
return false;
}
});
如何正确使用此脚本来处理php端的ID?
答案 0 :(得分:1)
var idValue = $('#avatar-id').val();
$.ajax({
type: "POST",
dataType:"html",
url: "delete_list.php",
data: {id: idValue},
success: function(response) {
location.reload(true);
}
});
答案 1 :(得分:0)
简单地说,
<强> jquery的强>
data: $('input#avatar-id').val(),
<强> PHP 强>
要在php中访问,请使用$_POST['id']