我不知道這是否可能,但任何幫助將不勝感激。提交<a> href到PHP
我通常使用javascript將我的html表單提交給外部php腳本。 共振是一個很好的方式顯示錯誤通知的JavaScript句柄。
下面是一個例子;
<script>
$("input#submit").click(function() {
$('#loader').show();
// Client side validation
if ($("#category").val() == "") {
$('#loader').hide();
detError();
} else {
$.post($("#cat-form").attr("action"),
$("#cat-form :input").serializeArray(),
function(response) {
switch (response) {
case "Valid":
$('#loader').hide();
catSuccess();
$('#cat-form').trigger("reset");
setTimeout(function() {
window.location.href = "blog_admin_categories.php";
}, 4000);
break;
case "not Valid":
$('#loader').hide();
catError();
break;
}
});
}
$("#cat-form").submit(function() {
return false;
});
});
</script>
正如你所看到的,根據我從PHP
腳本(有效,無效等),我運行另一個函數,也許刷新頁面回波接收響應。
現在我想用鏈接<a>
來做到這一點。
<a class='link' id='delete-link' href=/blog/php/blog_category_delete.php?delete='$cat_id'>Delete</a>
我該怎麼做?
在下面的答案幫助下,我現在有這個工作... 下面的代碼;
<script>
$("a.delete").click(function(event) {
event.preventDefault(); // this is needed to stop the browser from changing the site
var href = $(this).attr('href');
$.post($(this).attr('href'),
$('href').serializeArray(),
function(response) {
switch(response) {
case "Valid":
$('#loader').hide();
catDeleted();
$('#cat-form').trigger("reset");
setTimeout(function(){window.location.href="blog_admin_categories.php";},3000);
break;}
});
});
</script>
你是說你想你刪除做類似的帖子,並得到類似的迴應? – gfrobenius
只需在''上放置一個.click()處理程序,就像處理表單的提交按鈕一樣。 –