无法在我的代码中解析JSON

时间:2014-06-09 20:28:15

标签: javascript jquery html json

请帮我解决我的代码问题。我试图用getJSON填充html中的表。我得到的是getJSON内的警报,但不是$ .each(jso,function(i,j)里面的警告。提前谢谢。

<!DOCTYPE html>

    <html>
    <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>#{name}</title>
    <link rel="stylesheet"  href="css/jquery.mobile-1.3.2.min.css" />

    <script src="js/cordova-2.5.0.js"></script>

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

    <script src="js/jquery.mobile-1.3.2.min.js"></script>

    <script src="js/database.js"></script>

    <script src="js/FileAPI.js"></script>

    <script src="js/jquery.form.js"></script>

    <script src="js/filesystem.js"></script>
    <script src="js/listutils.js"></script>
    <style>

    </style>
    </head>

    <body>

        <div data-role="page" data-overlay-theme="d">
            <div data-role="header" class="ui-bar-b">
                <a onclick="onBackKeyDown();" data-icon="back" id="back">Back</a>
                <h1 id="header">Outlet Visit Report</h1>
                <a onclick="onUploadPhoto();" data-icon="check" id="send">Send</a>

        </div>


                <form action="#" method="post" enctype="multipart/form-data">

                <table id="myTable"> 
                <th>Item Code</th>
                <th>Item Description</th>
                <th>MRP</th>
                <th>Initial Quantity</th>
                <th>Current Quantity</th>
                <th>Refill Quantity</th>
                <th>Out of Stock</th>

                </table>


                <div style="display: none">
                        <input type="hidden" name="user" id="user" />
                        <input type="hidden" name="data" id="data" />

                </div>
                </form>

                <a data-transition="pop" id="busypop" style="display: none"
                    href="#positionWindow" data-rel="popup" data-position-to="window">
                </a>
                <div data-role="popup" id="positionWindow" data-dismissable="false"
                    data-theme="d" data-tolerance="15,15" class="ui-content"
                    data-position-to="window">

                    <ul data-role="listview" data-theme="d" data-divider-theme="b"
                        data-inset="true">

                        <li data-role="list-divider">Update Status</li>
                        <li data-role="fieldcontain">

                            <p>Please wait.Upload is in Progress........</p>
                        </li>
                    </ul>


                </div>




            <div data-role="popup" id="popupMap" data-overlay-theme="a" data-theme="a" data-corners="false" data-tolerance="15,15">

                <a href="#" data-rel="back" data-role="button" data-theme="a" data-icon="delete" data-iconpos="notext" class="ui-btn-right">Close</a>

                <iframe id="imframe" src=""  seamless></iframe>

            </div>

            <a id="opM" href="#popupMap" data-rel="popup" data-position-to="window"  data-theme="b" data-inline="true"></a>


        </div>

        <script>

        var user = "KBM";
        var base="";


        $(document).ready(function(){

        window.onload = devideReady();

            fetchData();    


        });


        function devideReady(){
            document.addEventListener("backbutton", function(){
                $("#back").click();
            }, false);
            initDatabase();
            readProperty(function(data){
                if(data!=null){
                    user = data['user'];
                }

            });
        }
        document.addEventListener("deviceready",devideReady, true);
        function getUser() {
            if(!isMobile.any()){
                return "admin";
            }
            return user;
        }
        var backHtml="";

        function onBackKeyDown() {
            window.open('mainpage.html',"_self");
        }

        function fetchData(){
        alert("before getJSON");
    $.getJSON("http://appkbm.appspot.com/jsp/index.jsp?action=json&user="+user+"&name=Item",function(jso){
            alert("After the query");
            var arr = new Array();
            $.each(jso,function(i,j){
            alert("Inside the Loop");
            var obj = (jQuery.parseJSON(j.data))[0];
            arr.push(obj);
            });

            $.each(arr,function(i,j){
                $("#table").append("<tr><td><input type="hidden" name="itemCode" id="itemCode" value ="+j['ITEM CODE']+" /></td><td><input type="text" name="itemDescription" id="itemDescription" value ="+j['ITEM DESCRIPTION']+" /></td><td><input type="text" name="mrp" id="mrp" value ="+j['SKU MRP']+" /></td><td><input type="text" name="initialQuant" id="initialQuant" /></td><td><input type="text" name="currentQuant" id="currentQuant" /></td><td><input type="text" name="refillQuant" id="refillQuant" /></td><td><input type="text" name="outOfStock" id="outOfStock" /></td></tr>");
                });
    });
    }
    </script>
    </body>
    </html>

0 个答案:

没有答案