Q: Ajax error checking - how to keep content from changing if AJAX request failed? I wasn't exactly sure how to clearly word my question --
I've got a simple ajax request on a checkbox that sends a value to a database.
I want to keep the checkbox from changing if the ajax request fails for any reason.  The way it currently works is if the request fails, it won't change the first time I click it.  But if I click again, it will change even though the request still failed. 
Here is the code:
<script type="text/javascript">
    $(document).ready(function(){
        $("#favorite").change(function() { 
            if($(this).is(":checked")) { 
                $.ajax({
                    url: 'favorite.php',
                    type: 'POST',
                    data: { file_id:$(this).attr("name"), strState:"1" },
                    success: function() { // this happens after we get results
                        $("#favWrap").empty();
                        $("#favWrap").html("<input id='favorite' name='165' type='checkbox' checked/><label></label>");
                    },
                    error:function(){
                        $("#favWrap").empty();
                        $("#favWrap").html("<input id='favorite' name='165' type='checkbox' /><label></label>")
                    }
                });
            } else {
                $.ajax({
                    url: 'favorite.php',
                    type: 'POST',
                    data: { file_id:$(this).attr("name"), strState:"0" },
                    success: function() { // this happens after we get results
                        $("#favWrap").empty();
                        $("#favWrap").html("<input id='favorite' name='165' type='checkbox' /><label></label>");
                    },
                    error:function(){
                        $("#favWrap").empty();
                        $("#favWrap").html("<input id='favorite' name='165' type='checkbox' checked/><label></label>")
                    }
                });
            }
        }); 
    });
</script>

Any help much appreciated!

A: If error comes in response than you can just check or uncheck the checkbox using 
$('#favorite').attr('checked', true); // Checks it
$('#favorite').attr('checked', false); // Unchecks it
