jquery - how to fetch json data from url? -


i not able fetch inside elements of json data. here's link json data.

here's code:

$(document).ready(function() {      //after button clicked download data     $('.button').click(function(){          //start ajax request         $.ajax({             url: "http://www.miamia.co.in/dummy/?json=get_recent_posts",             //force handle text             datatype: "text",             success: function(data) {                  //data downloaded call parsejson function                  //and pass downloaded data                 var json = $.parsejson(data);                 //now json variable contains data in json format                 //let's display few items   $('#results').html('pages:'+ json.pages + '<br />postid: '+json.posts.id);//here not able id              }         });     });  }); 

things note:

  1. datatype: "json"
  2. data returned json, there no need parse json
  3. it data.posts[0].id , not data.posts.id

the following demo works. can examine json content returned in console.log or in developer console of browser.

$(document).ready(function() {      //after button clicked download data    $('body').on("click", "#button", function() {        //start ajax request      $.ajax({        url: "http://www.miamia.co.in/dummy/?json=get_recent_posts&callback=?",          datatype: "json",        success: function(data) {          console.log(data);          //let's display few items          $('#results').html('pages:' + data.pages + '<br />postid: ' + data.posts[0].id); //here not able id        }      });    });  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>  <div id="results">    </div>  <input id="button" type="button" value="get posts">


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -