我似乎无法让这个工作。页面不显示

时间:2013-11-01 19:02:35

标签: javascript jquery html json

抱歉,如果这很难读,但我无法让它发挥作用。我一直在扫描代码寻找一些小错误,比如缺少半冒号和逗号。但是,我不知道是否有什么我做错了或者我只是错过了一点点花絮。无论。有什么我做错了吗?

我让程序现在正常运行!非常感谢,抱歉这个愚蠢的问题(从投票数量来看)。谢谢!

<!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>

4 个答案:

答案 0 :(得分:2)

你的JSON有一些缺少的逗号和一个额外的逗号(在数组的末尾,并非所有的浏览器都抱怨这个)。如:

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

结帐JSONLint.com),以及其他答案中指出的问题。这是修复了这些问题的demo

答案 1 :(得分:1)

尝试

$("#container1").html(

实际选择具有该ID的div

答案 2 :(得分:1)

使用jQuery,您需要使用哈希符号通过id引用对象,如此

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

答案 3 :(得分: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
}
相关问题