-2
我有一個包含兩列的表:名稱和複選框之一。單擊複選框時更新SQL而不重新加載整個頁面
我有一個id
列,name
列和複選框的一列相應的SQL數據庫。
我已經得到了網頁自動提交檢查/取消選中和修改SQL數據庫的基礎上,每個框是否選中或未選中,但我不知道如何做到這一點,沒有整個頁面重新加載。
我不是很熟悉AJAX,但認爲這可能是我需要的。任何人都可以指引我走向好的資源嗎
謝謝!
我有一個包含兩列的表:名稱和複選框之一。單擊複選框時更新SQL而不重新加載整個頁面
我有一個id
列,name
列和複選框的一列相應的SQL數據庫。
我已經得到了網頁自動提交檢查/取消選中和修改SQL數據庫的基礎上,每個框是否選中或未選中,但我不知道如何做到這一點,沒有整個頁面重新加載。
我不是很熟悉AJAX,但認爲這可能是我需要的。任何人都可以指引我走向好的資源嗎
謝謝!
是的,這應該與$.ajax()
完成。當然,請使用jQuery library。
$('form').submit(function(e){
e.preventDefault(); // the page will no longer refresh.
var that = $(this); //cache a reference to the form before our $.ajax
$.ajax({
type: that.prop('method'), //use the method of the form for the ajax call (post/get)
url: that.prop('action'), //use the action of the form as the url for the ajax call
data: that.serialize(), //send the form elements and their respective values
success: function(data){
//if your script returns any data it will be held within the "data" variable
console.log(data); //log data to the console
}
});
});