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

4 回答 4

2

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

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

Checkout JSONLint.com), as well as the issues pointed out in other answers. Here is a demo with these issues fixed.

于 2013-11-01T19:07:35.200 回答
1

尝试

$("#container1").html(

实际选择具有该 id 的 div

于 2013-11-01T19:05:06.343 回答
1

使用 jQuery,您需要使用井号来通过 id 来引用对象,如下所示

$("#container1").html( ... ...
   ^
于 2013-11-01T19:05:50.773 回答
0

Your JSON is invalid , several commas missing

{
"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
}
于 2013-11-01T19:13:31.473 回答