2015-04-12 94 views
0

我用一些Javascript代碼解析JSON數據。然而,當我使用完全相同的JSON的不同URL時,該代碼完全適用於一個JSON URL(請參見下文),但它不起作用,即頁面爲空白,而不是填充數據。以下是下面的JSON文件。如果你並排打開它們,你可以看到它們是相同的。 工作:https://dl.dropboxusercontent.com/u/97584761/JSON/Grad%20Jobs%20Ireland/staff-academic.json 不工作:http://appmakeit.com/directory/staff/staff-academic.json 同樣的工作,但結構化程度較低:https://staff-academic.firebaseio.com/.jsonJavascript JSON不解析

我真的想在appmakeit URL的JSON工作。這裏是我用來解析這個JSON的Javascript。您能否告訴我需要用Javascript修改才能成功解析此JSON。

$.ui.ready(function(){ 
    getData1("http://appmakeit.com/directory/staff/staff-academic.json"); 
}); 

function getData1(url) { 
    $.getJSON(url, function(data){ 
     var list_html = ""; 
     for(var i=0; i< data.staff1.length; i++){ 
      var id = data.staff1[i].id; 
      var fullname = data.staff1[i].fullname; 
      var position = data.staff1[i].position;    
      var location = data.staff1[i].location; 
      var phone = data.staff1[i].phone; 
      var email = data.staff1[i].email;    
      var photo = data.staff1[i].photo; 
      var profile = data.staff1[i].profile; 

      list_html += '<li2><a href="#'+id+'" class="icon user">&nbsp;'+ fullname +'</a></li2>'; 

      var panel_content = '<form><br><ul class="list inset" style="font-size: 16px;"><li2 class="divider">'+fullname+'</li2><br><div style="height:150px;width:100%;float:left;"><img src="'+photo+'" width="110" height="120" style="float:left; margin: 0px 10px -2px 8px; box-shadow: 1px 1px 8px #888888;"/><p><blockquote><strong>Position: </strong>'+position+'<br><br></div><strong><blockquote>&nbsp;&nbsp;Location: </strong>'+location+'</blockquote><br><br><strong><blockquote>&nbsp;&nbsp;Phone: </strong>'+phone+'</blockquote><br><br><strong><blockquote>&nbsp;&nbsp;Email: </strong>'+email+'</blockquote><br><br><center><a href="'+profile+'" target=」_blank」 class="button block" style="float:right; width: 120px; background-color:#0065A3; color:#fff; border-width:.1em; border-color:#00ACEB; margin:0px 2px 0px 2px;">Profile</a><a href="mailto:'+email+'" target=」_blank」 class="button block" style="float:right; width: 120px; background-color:#0065A3; color:#fff; border-width:.1em; border-color:#00ACEB; margin:0px 2px 0px 2px;">Email</a></center><br><br></blockquote></p></ul><br></form><br>'; 

      $.ui.addContentDiv(id, panel_content, "People"); 
     } 
     $("#dataList1").append(list_html); 
    }); 
} 
+2

當你說它「不工作」時,你的意思是什麼?你在控制檯中遇到錯誤嗎?錯誤的結果?還有別的嗎? – Pointy

+0

這些頁面只顯示爲空白。道歉,如果我不清楚 – Kerbol

+3

JavaScript控制檯說什麼?可以看到您在瀏覽器的開發人員工具中看到請求? – Quentin

回答

3

我猜你是想做一個Cross-origin要求,所以它不會讓你得到任何數據。

XMLHttpRequest cannot load http://insights.hotjar.com/api/v1/client/sites/13981/visit-data?sv=3. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://jsfiddle.net' is therefore not allowed access. The response had HTTP status code 500. 

他們不允許外部客戶端訪問這些資源,你應該檢查CURL但這是出於AJAX目的。

你後端是curl並返回資源您可以創建一個API,但是,無論如何,我不知道多少,這可以是「欣賞」(或者甚至是法律)

退房的fiddle