用jquery用html文本编写json数据的例子

Eur*_*nch 6 html jquery json

我是编程的初学者,我希望有人给我一个例子来告诉我如何JSONHTML文本写数据

<!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>
Run Code Online (Sandbox Code Playgroud)

Fel*_*ano 5

您可以在html中添加如下内容:

 <h2 id='lat'></h2>
    <h2 id='long'></h2>
    <h2 id='country'></h2>
Run Code Online (Sandbox Code Playgroud)

然后重构您的脚本:

$(document).ready(function(){

$.getJSON('http://api.wipmania.com/jsonp?callback=?', function (data) {

  $("#lat").text(data.latitude);  
  $("#long").text(data.longitude);  
  $("#country").text(data.country);      

});
 });
Run Code Online (Sandbox Code Playgroud)

这是一个可以玩的工作示例.