2016-09-04 29 views
1

JSON的位置:http://fooda.website/data_smaller.jsonJSON的問題,並實施一些現有的JavaScript到這個爛攤子

拼命地把這個JSON到一個表中的HTML,但也讓我來接我想要的特定對象(一些陣列具有在最終標記中不需要的對象)。

使用的代碼從這裏用「jput」:如果Parsing JSON objects for HTML table

不知道問題出在JSON或代碼,但沒有顯示當我加載頁面。

這裏是我的代碼:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<script src="jquery-1.12.3.min.js" type="text/javascript"></script> 
<script src="jput.min.js"></script> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Untitled Document</title> 
</head> 

<script> 
$(document).ready(function(){ 

var json = []; 
//while running this code the template will be appended in your div with json data 
$("#tbody").jPut({ 
    jsonData:json, 
    ajax_url:"data_smaller.json", 
    name:"tbody_template", 
}); 

}); 
</script> 

<table jput="t_template"> 
<tbody jput="tbody_template"> 
    <tr> 
     <td>{{First Name}}</td> 
     <td>{{Middle Name}}</td> 
    </tr> 
</tbody> 
</table> 

<table> 
<tbody id="tbody"> 
</tbody> 
</table> 

<script src="jquery.min.js"></script> 
<script src="jput.min.js"></script> 

</body> 
</html> 

只想代碼以顯示一個結果,也有一個按鈕,找到一個隨機排列和顯示。 最終產品是當按下時發現隨機數組並僅顯示特定對象的按鈕。

通過每一個可以想象的SO帖子,但我缺乏知識真的讓事情變得艱難,所以現在變得非常絕望。

幫助!

謝謝你......這個社區很棒。

+1

'nothing displays' - 在控制檯中怎麼樣?另外,你正在加載jquery(也許是兩個不同版本)和jput兩次 - 和「XHTML 1.0 Transitional」 - 真的嗎? –

回答

0

您從URL收到的json似乎是錯誤的,並且'body'標記丟失。你可以通過一些在線驗證器來驗證json。

JSON驗證:http://jsonlint.com/

下面的代碼足夠

$( 「#TBODY」)jPut({ ajax_url: 「http://fooda.website/data_smaller.json」, 前置:真實, 名稱: 「tbody_template」 , });

當你使用url時,不需要使用'var json'和jsonData:json。 jPut庫自動從Ajax URL獲取json。

+0

謝謝@Karpak!我已經做了一些編輯,但仍然無法讓事情發揮作用! 我已經嘗試了幾次JSON迭代,但事情仍然無法正常工作。 我有我的服務器上的文件: http://fooda.website/data_mini.json http://fooda.website/data_fixed.json http://fooda.website/data_fixed1.json HTTP: //fooda.website/data_smaller.json http://fooda.website/data.json http://fooda.website/data1.json – gezer4000

+0

也是JSfiddle這裏:https://jsfiddle.net/fwmcds4L/ 如果任何人都可以看到我在做什麼錯誤的代碼或JSON請讓我知道!謝謝! – gezer4000

1

首先,您的JSON無效,請嘗試JSONLint查找錯誤。

+1

它從這裏被打破:''相關的行爲':MC Eiht,' – zanderwar

相關問題