I'm looking to verify if my user has been updated from another system using JavaScript.
Can anyone assist me in creating a function that can analyze a JSON response and determine if it is true or false?
The URL /user/updatecheck/
provides a JSON response in the format: {"updated": "true"}
or {"updated": "false"}
<script type="text/javascript>
$(document).ready(function() {
var updated='2013-01-02T10:30:00.000123+02:00'; // user variable from the system, will be empty if the user is not updated
if (!updated) {
$('#not-updated').modal('show');
var updatedCheck = window.setInterval(
$.ajax({
url: "/user/updatecheck/", // Returns {"updated": "true"} or {"updated": "false"}
data: dataString,
dataType: "json",
success: function(data){
if (json.updated == 'true') { // unsure about this method
window.clearInterval(updatedCheck);
// The user has been updated - page needs to be reloaded
}
} // success
})
, 3000); // Hoping this is the function to check the URL every 3 seconds until it returns true
}
});
$(document).ajaxStop(function(){
window.location.reload();
});
</script>
This code doesn't seem to be functioning as expected. I am uncertain if my AJAX function is correct, as I only see the modal window when the user is not updated initially, and the page does not reload when the URL /user/updatecheck/
returns true.