2013-12-17 32 views
0

使用chrome的開發工具,我可以看到我的index.xhtml顯示狀態200正確 然而,當我點擊我的轉換按鈕時,轉換的數量不會顯示。 這裏是我的XHTML文件:fx.convert不能使用Money.js

<?xml version='1.0' encoding='UTF-8' ?> 
<!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" 
     xmlns:h="http://java.sun.com/jsf/html" 
     xmlns:f="http://java.sun.com/jsf/core"> 
    <h:head> 
     <title>Currency Exchange Rate Calculator</title> 
     <meta charset="utf-8"/> 
     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 
     <script src="money.js"></script> 
     <script src="accounting.js"></script> 
     <script src="http://openexchangerates.org/api/latest.json?app_id=e6b775e4bbde4ae19dd7294c39d71b15"></script> 
     <script src="http://openexchangerates.org/api/currencies.json?app_id=e6b775e4bbde4ae19dd7294c39d71b15"></script> 
     <script src="http://openexchangerates.org/api/historical/2011-10-18.json?app_id=e6b775e4bbde4ae19dd7294c39d71b15"></script> 
     <link rel="StyleSheet" type="text/css" href="apricot.css"></link> 
     <script type="text/javascript"> 
      // Load exchange rates data via the cross-domain/AJAX proxy: 
      $(document).ready(function() { 
      function load(){ 
       $.getJSON(
       'http://openexchangerates.org/latest.json?app_id=e6b775e4bbde4ae19dd7294c39d71b15', 
       function(data) { 
        // Check money.js has finished loading: 
        if (typeof fx != "undefined") { 
         fx.rates = data.rates; 
         fx.base = data.base; 
         alert("fx loaded"); 
        } else { 
         // If not, apply to fxSetup global: 
         alert("fx not loaded"); 
         var fxSetup = { 
          rates : data.rates, 
          base : data.base 
         } 
        } 
       } 
      ).error(function(error){console.log(error);}); 
       return false;  
      } 
}); 
      function convert(){ 
       //load(); 
       var fromelement = document.getElementById('xrate:fromcur'); 
       var from=fromelement.value; 
       var toelement = document.getElementById('xrate:tocur'); 
       var to = toelement.value; 
       var amtelement =document.getElementById('xrate:amt'); 
       var amt = amtelement.value; 
       alert("from = "+from+" to = "+to+" amount = "+amt); 

       //fx.settings = { from: from, to: to }; 
       var conv=fx.convert(amt,{ from: from, to: to }); 
       alert("conv = "+conv); 
       //fx.settings = { from: from, to: to }; 
       //var conv=fx.convert(amt); // 647.71034 
       var convelement = document.getElementById('xrate:result'); 
       convelement.value=conv; 

      } 

     </script> 
    </h:head> 
    <h:body> 
     <div id="welcome"> 
      <h:form id="xrate"> 
       <h:panelGrid columns="2" style="background-color: yellow"> 

        <h:outputLabel value="Select Currency From" for="fromcur" /> 
        <h:selectOneListbox id="fromcur" size = "1" value="xxx" title="xxx" > 
         <f:selectItem id="si0" itemLabel=" " itemValue=" " /> 
         <f:selectItem id="si1" itemLabel="RON" itemValue="RON" /> 
         <f:selectItem id="si2" itemLabel="EUR" itemValue="EUR" /> 
         <f:selectItem id="si3" itemLabel="CAD" itemValue="CAD" /> 
         <f:selectItem id="si4" itemLabel="GBP" itemValue="GBP" /> 
         <f:selectItem id="si5" itemLabel="USD" itemValue="USD" /> 
         <f:selectItem id="si6" itemLabel="MXP" itemValue="MXP" /> 
         <f:selectItem id="si7" itemLabel="CNY" itemValue="CNY" /> 
        </h:selectOneListbox> 
        <h:outputLabel value="Select Currency To" for="tocur" /> 
        <h:selectOneListbox id="tocur" size = "1" value="xxx" title="xxx" > 
         <f:selectItem id="ti0" itemLabel=" " itemValue=" " /> 
         <f:selectItem id="ti1" itemLabel="RON" itemValue="RON" /> 
         <f:selectItem id="ti2" itemLabel="EUR" itemValue="EUR" /> 
         <f:selectItem id="ti3" itemLabel="CAD" itemValue="CAD" /> 
         <f:selectItem id="ti4" itemLabel="GBP" itemValue="GBP" /> 
         <f:selectItem id="ti5" itemLabel="USD" itemValue="USD" /> 
         <f:selectItem id="ti6" itemLabel="MXP" itemValue="MXP" /> 
         <f:selectItem id="ti7" itemLabel="CNY" itemValue="CNY" /> 

        </h:selectOneListbox> 

        <h:outputLabel value="Enter Amount" for="amt" /> 
        <h:inputText id="amt" style="color:red;background-      color:yellowgreen" size="10"/> 
        <h:commandButton value="Calculate" id="calc" onclick="convert()"/> 
        <h:outputText id ="result" style="color:blue;border:5px solid tan;" /> 

       </h:panelGrid> 
      </h:form> 
     </div> 
    </h:body> 
</html> 

enter code here 

我使用一個鏈接到openexchangerates.org 任何幫助將不勝感激。 謝謝。

回答

0

我在代碼中發現我的錯誤。 因此對於任何有興趣的人來說,這項工作現在很好:

  <script type="text/javascript"> 
     // Load exchange rates data via the cross-domain/AJAX proxy: 
     //   $(document).ready(function() { 
     $.getJSON(
     'http://openexchangerates.org/latest.json?app_id=e6b775e4bbde4ae19dd7294c39d71b15', 
     function(data) { 
      // Check money.js has finished loading: 
      if (typeof fx != "undefined") { 
       fx.rates = data.rates; 
       fx.base = data.base; 
       //alert("fx loaded"); 
      } else { 
       // If not, apply to fxSetup global: 
       //alert("fx not loaded"); 
       var fxSetup = { 
        rates : data.rates, 
        base : data.base 
       } 
      } 
     } 
    ) 


     //   }); 
     function convert(){ 
      //load(); 
      var fromelement = document.getElementById('xrate:fromcur'); 
      var from=fromelement.value; 
      var toelement = document.getElementById('xrate:tocur'); 
      var to = toelement.value; 
      var amtelement =document.getElementById('xrate:amt'); 
      var amt = amtelement.value; 
      alert("from = "+from+" to = "+to+" amount = "+amt); 

      //fx.settings = { from: from, to: to }; 
      var conv=fx.convert(amt,{ from: from, to: to }); 
      alert("conv = "+conv); 
      //fx.settings = { from: from, to: to }; 
      //var conv=fx.convert(amt); // 647.71034 
      var convelement = document.getElementById('xrate:result'); 
      convelement.value=conv; 
      //document.getElementById('xrate:result').value=conv; 

     }