2017-04-02 48 views
0
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} 
    }); 
}); 

我想重定向到的位置與數據一起,在我的情況下不能使用形式如何發送(AJAX)POST數據到網址並重定向到具有相同數據的網址?

+0

您能否解釋*爲什麼*您無法使用表格? – Phil

+0

因爲我點擊使用圖像,通過使用jquery我正在採取的屬性和鏈接到PHP的網址 – Y07

+0

您仍然可以使用圖像點擊提交表單。請參閱[''](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/image) – Phil

回答

0

成功屬性我不看到任何涉及JavaScript的理由。

如果你想點擊圖片,並通過POST提交的數據,只需使用類似

<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() 
}) 
0

$(".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}, 
 
    success: function(data){ 
 
    alert(data.data); 
 
    } 
 
    }); 
 
    });

添加AJAX

相關問題