mercredi 2 mars 2016

checkbox: change state of checkbox by Ajax

I am using checkbox in my php file.

<label>
    <input type="checkbox" id="response" name="response" value="email">Email
</label>

I am retrieving the data from database by using Ajax. I want to change the state of checkbox as per the database data. In database data are 0 or 1.

I can see data is coming properly from database but i don't know how can i use that to change state of checkbox.

$("#autofill").change(function () {
    $.ajax({
        type: "GET",
        url: "autofill.php",
        cache: false,
        // dataType: 'json',
        data: 'action1=' + data1,
        success: function (data) {
            data = JSON.parse(data);
            $('#response').val(data.response);
        }
    })
});

As per my understanding $('#response').val(data.response); will not work. But not sure what do i need to put there.

Thanks guys.




Aucun commentaire:

Enregistrer un commentaire