how to save checkbox state wehn page is reload

how to save checkbox state wehn page is reload

Hi, I have a checkbox, I've defined two state for it, and when I reload page, this checkbox back to the default state (or unchecked). I got in trouble at the forum, but I did not get my answer. This is my code. : $ (document). ready ( function () {
    $('#mycheckbox').change(function () {
var returnVal = ("Are " + "you sure?");
if (returnVal) {
postToServer($(this).prop("checked"));


} else {
$(this).prop("checked", !$(this).is(":checked"));

}
});


function postToServer(state) {
let value = (state) ? 1 : 0;
//alert('Posted Value: ' + value);
$.ajax({
type: 'POST',
url: 'checkbox.php',
data: {'value': +value},
success: function (response) {
//handle response
}
});
}
window.onload = function() {
if(window.location.hash === '#checkmeClicked') {
$("#checkme").click();
}
}
});
and html code: <input type= "checkbox" class= "checkbox" id= "mycheckbox" name= "chb" />