-3

i have read json data in javascript. but json data not display first time page load, its load after refresh page. Please solve my problem. here is my code:

$(document).ready(function () {
  $.ajax({
            url:"http://192.168.0.105/stratagic-json/project_json.php",
            type:"GET",
            dataType:"json",
            beforeSend: function(){
            success:function(jsonData){
     var projctList = '';

  for (var i = 0; i < jsonData.length; i++) {
      projctList += ' <li><div class="proj-details-wrap"> <img src="images/project-img.jpg" /><div class="proj-badge">Upcoming Projects</div><div class="proj-name">'+ jsonData[i].name +'<span>'+ jsonData[i].location +'</span> </div><div class="proj-status">'+ jsonData[i].percentage +'% <span>completed</span> </div></div><div class="container proj-desc">'+ jsonData[i].description +' </div> </li>';
     }
          $("#projctLists").html(projctList);

     }
     }); 
});

1 Answers1

0

A quick Google search would've shown you how to use JSON.parse:

console.log(JSON.parse('[ { "id": "1", "title": "Mr", "name": "neeraj", "mobile": "9076123344", "emailID": "neerajt43@gmail.com", "projname": "Aryan Heights", "subproj": "A Wing", "unit": "Pent House", "budget": "25 to 30 Lacs", "comments": "This is test Comment" }, { "id": "3", "title": "Mr", "name": "neeraj", "mobile": "9076554744", "emailID": "neerajt43@gmail.com", "projname": "Aryan Heights", "subproj": "A Wing", "unit": "Row House", "budget": "25 to 30 Lacs", "comments": "This is test" } ]'));
Shomz
  • 37,421
  • 4
  • 57
  • 85