I'm quite new to JSON handling and I've got myself stuck. My page contains the following script;
<script type="text/javascript">
$(document).ready(function() {
$('#progressBar').progressbar({value: 0.0});
process();
});
function process() {
getStatus();
setInterval(getStatus,1000);
}
function getStatus() {
$.getJSON('status-report', function(data) {
var statusBean = $.parseJSON(data);
$('#progressBar').progressbar('option','value',$.trim(statusBean.percentComplete));
$('#status').html(statusBean.statusDescription);
});
}
</script>
Using Firebug, I can see that the call to 'status-report' is returning a JSON string
{"statusBean":{"percentComplete":50.0,"statusDescription":"Default Description"}}
but after $.parseJSON, Firebug shows me that the variable statusBean is null.
What am I doing wrong?
datais already a JavaScript object.getJSONparses the response for you. It is described in the documentation: "Thesuccesscallback is passed the returned data, which is typically a JavaScript object or array as defined by the JSON structure and parsed using the$.parseJSON()method.".