Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I write json results to a div using jquery?

Tags:

json

jquery

This is probably a really easy question, but I can't find anything that works.

I'm trying to take a json result and just write it into the inner html of a div to see what it looks like.

I have something like this:

$.getJSON("someurlthatgivesmejson",
    function(data){         
        $("#jsonmodel").html(data);  // what should this be??
    });
  });

UPDATE

I was able to get it to display some text by using

$("#jsonmodel").html($.param(data));

However, it's not formatted like how the browser displays a json result, like the structure of the javascript object.

like image 840
Joseph Avatar asked Jan 24 '23 06:01

Joseph


1 Answers

You can use jquery-json library

`$('#jsonmodel').html($.toJSON(data));`
like image 193
Jirapong Avatar answered Jan 25 '23 18:01

Jirapong