This seems really bizarre…
I have some JSON…
{"firstName":"David","lastName":"Smith","email":null,"id":0}
But when I try to parse it and use it with…
<script>
$(document).ready(function() {
var json = $.getJSON('userManagement/getUser');
$("p").text(json.firstName);
});
</script>
This is the user management view
Users : <p></p>
Nothing appears, but if I just do $(“p”).text(json); it tells me it’s an object and I can see the JSON is correct in firebug, any ideas?
Try:
You have to work with the
jsonvariable after the AJAX request has completed.Learn more here about AJAX JSON Requests: http://api.jquery.com/jQuery.getJSON/
Learn more here about general AJAX Requests: http://api.jquery.com/jQuery.ajax/