Windows Phone无法使用$ getJSON加载本地JSON文件

时间:2012-07-30 09:52:47

标签: windows-phone-7 jquery-mobile cordova

我现在用Phonegap Cordova 2.0.0和Jquery Mobile 1.1.1 final实现Windows Phone 由于Window Phone Emulator没有加载JSON数据,我将无法使用本地JSON文件 iOS和Android模拟器平稳运行时<select>元素。这是我的代码段

<!DOCTYPE html> 
<html> 
    <head> 
        <title>Page Title</title> 

        <meta name="viewport" content="width=device-width, initial-scale=1"> 
        <link rel="stylesheet" href="css/jquery.mobile-1.1.1.min.css" />
        <link rel="stylesheet" href="css/jqm-icon-pack-2.1.2-fa.css" />
        <script type="text/javascript" src="js/cordova-2.0.0.js"></script>
        <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
        <script type="text/javascript" src="js/jquery.mobile-1.1.1.min.js"></script>
        <script type="text/javascript" src="js/json2.js"></script>
        <script type="text/javascript" charset="utf-8">

            function changeBaseAmount() {
                alert($('#baseAmount').val());
            }

        $.getJSON('json/currencies.json',
            function (data) {
                alert("get json");
                $.each(data, function (key, value) {

                    $('#currency1').append("<option value='" + key + "'>" + value + "</option>");

                    $('#currency2').append("<option value='" + key + "'>" + value + "</option>");

               });

           });



    </script>
    </head> 

    <body> 
        <!-- Home Page -->
        <div data-role="page" data-theme="b">
            <div data-role="header" data-theme="b">

                <h1>Convert Currency</h1>
                <a href="#" data-role="button" data-icon="wrench" data-iconpos="notext"></a>
            </div> 

            <div data-role="content" data-theme="b">

                <div id="baseAmountDiv" data-role="fieldcontain">
                    <label for="baseAmount">Amount:</label>
                    <input id="baseAmount" type="text" value="" onchange="changeBaseAmount()"></input>
                </div>
                <div id="currency1Div" data-role="fieldcontain">
                    <label for="currency1">Currency From:</label>
                    <select id="currency1" onchange="changeCurrency1()">
                        <option value="ZZ">Please Select Currency From</option>
                    </select>
                </div>
                <div id="currency2Div" data-role="fieldcontain">
                    <label for="currency2">Currency To:</label>
                    <select id="currency2" onchange="changeCurrency2()">
                        <option value="ZZ">Please Select Currency To</option>
                    </select>
                </div>
                <div id="resultAmountDiv" data-role="fieldcontain">
                    <label for="resultAmount">Result:</label>
                    <input id="resultAmount" type="text" value="" readonly="readonly" style="background-color: silver"></input>
                </div>
            </div> 

            <div data-role="footer" data-theme="b"></i></div> 
        </div>
    </body>
</html>

1 个答案:

答案 0 :(得分:0)

Cordova for WP7有自己的XHR请求实现,以支持获取本地数据。请参阅以下内容:

https://issues.apache.org/jira/browse/CB-208

您可能必须使用$.ajax才能使其正常运行。