I have to display a JSON data in a web page on button click
<table>
<tr>
<td style="height:10px;">
<div id="testResult" style="padding-left: 120px; display: none; ">
<img src="./images/spinner.gif" />Running the test...
</div>
</td>
</tr>
</table>
It s the html data am using
Bellow is the code written in the button click
$('#runBtn').click(function() {
$.get('/getReport', function (data) {
alert(data) // prints [{ "id" : 16, "jobid" : "49", "status" : "Falied" }]
$('#testResult').html(data);
});
}
But nothing is showing in the web page
testResultelement hidden?<div id="testResult" style="... display: none; ">runBtnin there.alert()doesn't print[object Object]this means that jQuery doesn't parse the response, you should either parse the JSON yourself usingJSON.parse()or pass thedataTypeas the third argument to$.get(url, fn, 'json')function.jQuery.getJSON(). If they parse it from a string to an array, however, they can't just pass that directly to.html()- jQuery has no idea what to do with that (it just seems to fail silently)..html()doesn't do anything with that array, I assumed setting the JSON response as innerHTML of an element is not the OP's final goal.