【问题标题】:Update SQL when checkbox is clicked without reloading entire page [closed]单击复选框而不重新加载整个页面时更新 SQL [关闭]
【发布时间】:2023-03-18 18:58:01
【问题描述】:

我有一个包含两列的表:一列名称和一列复选框。

我有一个相应的 SQL 数据库,其中包含一个 id 列、name 列和一列用于复选框。

我已经让网页自动提交选中/取消选中并根据每个框是否选中或未选中来修改 SQL 数据库,但是如果不重新加载整个页面,我无法弄清楚如何做到这一点。

我对 AJAX 不是很熟悉,但认为这可能是我需要的。谁能指导我寻找好的资源?

谢谢!

【问题讨论】:

    标签: php sql ajax


    【解决方案1】:

    是的,这应该通过$.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
            }
        });
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-28
      • 1970-01-01
      • 2013-09-18
      • 2016-04-19
      • 1970-01-01
      • 2018-04-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多