Example for writing json data using jquery with html text

I am starting to program, I want someone to give me an example to show me how to write JSON data with HTML text

 <!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery-1.8.3.min.js"></script> </head> <body> <h1>antar<h2> <script> $.getJSON('http://api.wipmania.com/jsonp?callback=?', function (data) { document.open(); document.write('Latitude: ' + data.latitude + '\nLongitude: ' + data.longitude + '\nCountry: ' + data.address.country); document.close(); }); </script> </body> </html> 
+6
source share
2 answers

You can add in your html something like:

  <h2 id='lat'></h2> <h2 id='long'></h2> <h2 id='country'></h2> 

and then reorganize the script as:

 $(document).ready(function(){ $.getJSON('http://api.wipmania.com/jsonp?callback=?', function (data) { $("#lat").text(data.latitude); $("#long").text(data.longitude); $("#country").text(data.country); }); }); 

Here is a working example that you can play with .

+5
source

use JSON.stringify and add it to any example DOM element using div with id mydiv

 var a = JSON.stringify(myJSON); document.getElementById('mydiv').innerHTML(a); 

Link:

https://github.com/douglascrockford/JSON-js

0
source

All Articles