货币转换器在jquery Mobile中

时间:2013-10-04 08:48:50

标签: jquery-mobile currency

我在JQuery Mobile的帮助下制作了一个Android应用程序。在这些应用程序中,我想转换用户想要的货币应该在全球检查它是当时和当天的货币汇率

在HTML5中: -

 <label for="amount">Convert this amount:</label>
    <input type="text" name="amount" id="amount" value="" />
 <div class="data">
    <label for="fromCurrency">From this currency:</label>
    <select name="fromCurrency" id="fromCurrency">
      <option selected="" value="EUR">Euro - EUR</option>
      <option value="USD">United States Dollars - USD</option>
      <option value="GBP">United Kingdom Pounds - GBP</option>
      <option value="CAD">Canada Dollars - CAD</option>
      <option value="AUD">Australia Dollars - AUD</option>
      <option value="JPY">India Rupees - JPY</option>
    </select>
</div>
<div class="data">
    <label for="toCurrency">To this currency:</label>
    <select name="toCurrency" id="toCurrency">
      <option value="USD">United States Dollars - USD</option>
      <option value="GBP">United Kingdom Pounds - GBP</option>
      <option value="CAD">Canada Dollars - CAD</option>
      <option value="AUD">Australia Dollars - AUD</option>
      <option value="JPY">Japan Yen - JPY</option>
      <option value="INR">India Rupees - INR</option>
    </select>
</div>

    <input type="button" name="convert" id="convert" value="Convert" />

    <div id="results"></div>

在JQuery中: -

  $(document).ready(function() {
     $('#convert').click(function(){
         var amount = $('#amount').val();
         var from = $('#fromCurrency').val();
         var to = $('#toCurrency').val();
         var dataString = "amount=" + amount + "&from=" + from + "&to=" + to;
            $.ajax({
               type: "POST",
               url: "http://www.google.com/ig/calculator?hl=en&q="+dataString,
               data: dataString,
               success: function(data){
                $('#results').show();
                $('#results').html(data);
               }
            });
         });
     });

我在这里犯的错误是什么呢?

请帮帮我

在head标签内我使用了以下脚本

  <meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

1 个答案:

答案 0 :(得分:1)

这是工作代码:

 $('#convert').click(function(){
         var amount = $('#amount').val();
         var from = $('#fromCurrency').val();

         var to = $('#toCurrency').val();
         var dataString = from + "&to=" + to + "&q=" + amount;

         $.ajax({
            type: "POST",
            crossDomain: true,
            dataType: 'jsonp',
            contentType: "application/json; charset=utf-8",   
            url: "http://rate-exchange.appspot.com/currency?from=" + dataString,
            success: function(data){
              alert(JSON.stringify(data));
              $('#results').show();
              $('#results').html(data.v);
            },error: function(xhr, status, error) {
              alert(xhr.responseText);
            }
        });
    });