2013-11-01 46 views
-5

對不起,如果這很難看,但我不能得到這個工作。我一直在掃描代碼,尋找諸如缺少分號和逗號的小錯誤。但是,我不知道是否有什麼我正在做的完全錯誤,或者我只是缺少一點點消息。無論。有什麼我做錯了嗎?我似乎無法得到這個工作。該頁面不顯示

我得到了程序現在的工作!非常感謝你,並且對這個愚蠢的問題感到抱歉(從票數來看)。謝謝!

<!DOCTYPE html> 
    <html lang="en"> 
    <head> 
    <meta charset="utf-8"> 
    <title> WEB204 </title> 
    <link rel="stylesheet" href="css/master.css"> 
    <script src="http://code.jquery.com/jquery-latest.min.js"></script> 
    <script> 
    var jsonData = { 
     "rows" : [ 
     { 
     "customer_id" : 148, 
     "customer_name" : "Al's Appliance and Sport", 
     "street" : "2837 Greenway", 
     "city" : "Fillmore", 
     "state" : "FL", 
     "ZIP" : 33336, 
     "balance" : 6550, 
     "credit_limit" : 7500, 
     "REP_ID" : 20 
     }, 
     { 
     "customer_id" : 282, 
     "customer_name" : "Brookings Direct", 
     "street" : "3827 Devon" 
     "city" : "Grove", 
     "state" : "FL", 
     "ZIP" : 33321, 
     "balance" : 431, 
     "credit_limit" : 10000, 
     "REP_ID" : 35 
     }, 
     { 
     "customer_id" : 356, 
     "customer_name" : "Ferguson's", 
     "street" : "382 Wildwood", 
     "city" : "Northfield", 
     "state" : "FL" 
     "ZIP" : 33146, 
     "balance" : 5785, 
     "credit_limit" : 7500, 
     "REP_ID" : 65 
     }, 
     { 
     "customer_id" : 408, 
     "customer_name" : "The Everything Shop", 
     "street" : "1828 Raven", 
     "city" : "Crystal", 
     "state" : "FL", 
     "ZIP" : 33503, 
     "balance" : 5285, 
     "credit_limit" : 5000, 
     "REP_ID" : 35 
     }, 
     { 
     "customer_id" : 462, 
     "customer_name" : "Bargains Galore", 
     "street" : "3829 Central", 
     "city" : "Grove", 
     "state" : "FL", 
     "ZIP" : 33321, 
     "balance" : 3412, 
     "credit_limit" : 10000, 
     "REP_ID" : 65 
     }, 
     { 
     "customer_id" : 148, 
     "customer_name" : "Kline's", 
     "street" : "838 Ridgeland", 
     "city" : "Fillmore", 
     "state" : "FL", 
     "ZIP" : 33336, 
     "balance" : 12762, 
     "credit_limit" : 15000, 
     "REP_ID" : 20 
     }, 
     { 
     "customer_id" : 608, 
     "customer_name" : "Johnson's Department Store", 
     "street" : "372 Oxford", 
     "city" : "Sheldon", 
     "state" : "FL", 
     "ZIP" : 33553, 
     "balance" : 2106, 
     "credit_limit" : 10000, 
     "REP_ID" : 65 
     }, 
     { 
     "customer_id" : 687, 
     "customer_name" : "Lee's Sport and Appliance", 
     "street" : "282 Evergreen", 
     "city" : "Altonville", 
     "state" : "FL", 
     "ZIP" : 32543, 
     "balance" : 2851, 
     "credit_limit" : 5000, 
     "REP_ID" : 35 
     }, 
     { 
     "customer_id" : 725, 
     "customer_name" : "Deerfield's Four Seasons", 
     "street" : "282 Columbia", 
     "city" : "Sheldon", 
     "state" : "FL", 
     "ZIP" : 33553, 
     "balance" : 248, 
     "credit_limit" : 7500, 
     "REP_ID" : 35 
     }, 
     { 
     "customer_id" : 842, 
     "customer_name" : "All Season", 
     "street" : "28 Lakeview", 
     "city" : "Grove", 
     "state" : "FL", 
     "ZIP" : 33321, 
     "balance" : 8221, 
     "credit_limit" : 7500, 
     "REP_ID" : 20 
     }, 
    ] 
    }; 
    </script> 


    <script> 
     $(document).ready(function() { 
      $("container1").html(
       "customer_id: "  + jsonData.rows[0].customer_id  + "<br/>" + 
       "customer_name: " + jsonData.rows[0].customer_name + "<br/>" + 
       "street: "   + jsonData.rows[0].street   + "<br/>" + 
       "city : "   + jsonData.rows[0].city    + "<br/>" + 
       "state: "   + jsonData.rows[0].state   + "<br/>" + 
       "ZIP: "    + jsonData.rows[0].ZIP    + "<br/>" + 
       "balance: "   + jsonData.rows[0].balance   + "<br/>" + 
       "credit length: " + jsonData.rows[0].credit_limit  + "<br/>" + 
       "REP_ID: "   + jsonData.rows[0].REP_ID   + "<br/>" + 
       "<br/>" 

       ); 

     }); 
     </script> 
     </head> 
     <body> 
      <div id="container1" class="narrow"> </div> 
     </body> 
    </html> 
+1

你有什麼錯誤控制檯看到了什麼? – SLaks

+1

必填註釋:那不是JSON。它只是一個JavaScript對象數組。 – JJJ

+0

「'street」後面缺少一個逗號:「3827 Devon」和「state」:「FL」 – j08691

回答

2

您的JSON有一些缺失的逗號和一個額外的逗號(在數組末尾,並非所有瀏覽器都抱怨 這個)。如:

"state" : "FL" 
"ZIP" : 33146, 

結帳JSONLint.com),以及這些問題在其他的答案中指出。這是修復了這些問題的demo

+0

我也嘗試了你的修復。 http://jsfiddle.net/3825/4czJN/4/ – kush

1

嘗試

$("#container1").html(

實際使用該ID

+0

這沒有幫助! –

+4

@LewisM。這是因爲你的代碼包含*多個*錯誤。 – meagar

+0

@meagar是的。我同意。非常抱歉,但我確實得到了工作。這真的有幫助! –

1

使用jQuery選擇div,你需要使用一個哈希符號指由ID對象,所以

$("#container1").html(... ... 
^
0

你JSON是無效的,幾個逗號,缺少

{ 
"customer_id" : 282, 
"customer_name" : "Brookings Direct", 
"street" : "3827 Devon",//here 
"city" : "Grove", 
"state" : "FL", 
"ZIP" : 33321, 
"balance" : 431, 
"credit_limit" : 10000, 
"REP_ID" : 35 
}, 
{ 
"customer_id" : 356, 
"customer_name" : "Ferguson's", 
"street" : "382 Wildwood", 
"city" : "Northfield", 
"state" : "FL",//here 
"ZIP" : 33146, 
"balance" : 5785, 
"credit_limit" : 7500, 
"REP_ID" : 65 
} 
相關問題