user4593889
user4593889

Reputation:

how to make ajax call onclick of checkbox

How to change this in ajax call. This is the jquery code which is calling the controller and getting the data from the database and onclick of checkbox filtering of data is happening and displaying the resulted data. Now my my requirement is do this thing with ajax call. How should I do.

$('input[name^="checkbox_"]').click(function () {
    $('#checkbox_all').prop('checked', false);
    var Status = $(this).val();
    if (Status == 'allocated') {
        var url = "statusAdmin.html?Status=" + Status;
        $(location).attr('href', url);
    }
});

Upvotes: 1

Views: 3053

Answers (1)

Rikard
Rikard

Reputation: 7805

To make the same with Ajax you need to change the logic like this:

$('input[name^="checkbox_"]').click(function () {
    $('#checkbox_all').prop('checked', false);
    var status = this.value;
    $.ajax({
        url: "statusAdmin.html?Status=" + status,
        success: function (res) {
            //do something with the response
        }
    });
});

Upvotes: 1

Related Questions