Php 如何将(AJAX)POST数据发送到url并重定向到包含数据的同一url?

Php 如何将(AJAX)POST数据发送到url并重定向到包含数据的同一url?,php,jquery,ajax,post,Php,Jquery,Ajax,Post,我想重定向到位置和数据,在我的情况下不能使用表单 $(“.w”)。单击(函数(){ var id=jQuery(this.attr('id'); 变量位置=”http://localhost:8888/Admin/description/description.php"; $.ajax({ url:位置, 类型:'POST', 数据:{data:id}, 成功:功能(数据){ 警报(数据、数据); } }); });我看不出有任何理由让JavaScript参与其中 如果你想点击一张图片并通过PO

我想重定向到位置和数据,在我的情况下不能使用表单

$(“.w”)。单击(函数(){
var id=jQuery(this.attr('id');
变量位置=”http://localhost:8888/Admin/description/description.php";
$.ajax({
url:位置,
类型:'POST',
数据:{data:id},
成功:功能(数据){
警报(数据、数据);
}
});

});我看不出有任何理由让JavaScript参与其中

如果你想点击一张图片并通过POST提交数据,只需使用

jQuery(".w").click(function() {
    var id =jQuery(this).attr('id');

    var location="http://localhost:8888/Admin/description/description.php";
    $.ajax({
        url: location,
        type:'POST',
        data:{data:id}
    });
});

你能解释一下为什么不能使用表单吗?因为我在单击时使用图像,所以通过使用Jquery,我获取属性并链接到php URL,你仍然可以使用图像单击来提交表单。看见
<form method="post" action="http://localhost:8888/Admin/description/description.php">
  <input type="image" name="data" value="your-id-value"
         src="/url/of/some/image">
</form>
jQuery('.w').on('click', function(e) {
  e.preventDefault(); // just in case
  const form = document.createElement('form')
  form.method = 'POST'
  form.action = 'http://localhost:8888/Admin/description/description.php'
  const input = document.createElement('input')
  input.type = 'hidden'
  input.name = 'data'
  input.value = this.id
  form.appendChild(input)
  form.submit()
})