checkbox - checked or unchecked with jquery and mysql

前端 未结 5 1487
清歌不尽
清歌不尽 2020-12-06 11:52

I am currently doing a system where it has to be possible to check/uncheck a checkbox. Everytime it changes status I need jquery to make and ajax call to a page, that update

5条回答
  •  一向
    一向 (楼主)
    2020-12-06 12:07

    Which bit are you stuck on? You should probably have something like this...

    $('#myCheckbox').click(function() {
        var checked = $(this).is(':checked');
    
        $.ajax({
            type: "POST",
            url: myUrl,
            data: { checked : checked },
            success: function(data) {
                alert('it worked');
            },
            error: function() {
                alert('it broke');
            },
            complete: function() {
                alert('it completed');
            }
        });
    });
    

提交回复
热议问题