简体   繁体   中英

Json uploading with jquery file error

    <!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.11.0.js"></script>
    <script type="text/javascript">
    function restults(data) 
    {
        $.each(data, function(index, data) 
        {
            alert(data.menu);
            $("#menu").append("<li>MenuID: " + data.MenuID + " OmfID: " + data.OmfID + " menu_name: " + data.menu_name + "</li>");
        });

    }
    $(document).ready(function()
    {
        setInterval(function() 
        {
            $.ajax(
            {
                type: "GET",
                dataType: "json",
                url: "json.json",
                success: function(data)
                {
                   restults(data);
                }
            });
        }, 1000);
    });
    </script>
    </head>
    <body>
    <div id="menu">
    </div>
    </body>
    </html>

this is my json file

[
{"menu":{"MenuID":"Test 1302662957","OmfID":"http:\/\/www.google.com","menu_name":"Zuker"}},
{"menu":{"MenuID":"Test 1302662957","OmfID":"http:\/\/www.google.com","menu_name":"Zuker"}},
{"menu":{"MenuID":"Test 1302662957","OmfID":"http:\/\/www.google.com","menu_name":"Zuker"}},
{"menu":{"MenuID":"Test 1302662957","OmfID":"http:\/\/www.google.com","menu_name":"Zuker"}},
{"menu":{"MenuID":"Test 1302662957","OmfID":"http:\/\/www.google.com","menu_name":"Zuker"}}
]

The way my javascript is set up now runs without {"menu": being in the json file but i have to have the {"menu": in the json file. my question is:

  1. How would i go about looping throughout the json file with {"menu":{ in the file??

Just makes some minor changes in the way it iterates

function restults(result) {
    $.each(result, function(index, data) {
        var menu = data.menu;
        var li   = $('<li />', {
            text : "MenuID: " + menu.MenuID + " OmfID: " + 
                    menu.OmfID + " menu_name: " + menu.menu_name
        });

        $("#menu").append(li);
    });
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM