-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
}
});
});