2012-07-30 67 views
1

我現在使用Phonegap Cordova 2.0.0和Jquery Mobile 1.1.1最終 實現Windows Phone,並且由於Window Phone模擬器的原因,我一直使用本地JSON文件不加載JSON數據 至<select>元素,而iOS和Android仿真器運行平穩。這是我的代碼段

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

回答

0

Cordova for WP7有自己的XHR請求實現,以支持獲取本地數據。請參閱以下內容:

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

您可能必須以使用$.ajax這才能正常工作。

+0

WP8模擬器,嘗試讀取本地xml文件時遇到同樣的問題,我收到錯誤消息「未連接。\ n驗證網絡」。 ......我的電話... $阿賈克斯({ \t \t類型: 「GET」, \t \t網址: 「RES /生/ puzzle_data.xml」, \t \t數據類型: 「XML」, \t \t成功:function(xml){... – 2012-11-05 15:50:38

相關問題