加载页面后不加载json数据

时间:2015-07-18 01:37:54

标签: javascript html json

我在javascript中读过json数据。但是json数据不会显示第一次页面加载,它在刷新页面后加载。请解决我的问题。 这是我的代码:

$(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 个答案:

答案 0 :(得分:0)

A quick Google search会向您展示如何使用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" } ]'));