gpt4 book ai didi

android - api在浏览器中工作但在android phonegap中不工作

转载 作者:行者123 更新时间:2023-11-29 20:16:42 24 4
gpt4 key购买 nike

我正在创建一个货币转换器,我正在从互联网上获取当前货币汇率,它在浏览器上正确获取值,但在 Android 手机上不起作用。 我在互联网上搜索了很多,但没有找到适合这个问题的有效解决方案。

请帮忙

<html>
<head>

<script src="../js/jquery.min.js"></script>
<script src="../js/jquery.mobile.min.js"></script>
<script src="../js/main.js"></script>
<script src="../cordova.js"></script>
<link rel="stylesheet" type="text/css" href="../css/main.css">
<link rel="stylesheet" href="../css/jquery.mobile-1.4.5.min.css" />

<script>

var audv;
var inrv;
var jpyv;
var rubv;
var gbpv;

$.ajax({

url: 'https://currency-api.appspot.com/api/USD/AUD.jsonp',
dataType: "jsonp",
data: {amount: '1.00'},
success: function(response) {

if (response.success) {

audv = parseFloat(response.rate).toFixed(2);

}
}
});

$.ajax({

url: 'https://currency-api.appspot.com/api/USD/INR.jsonp',
dataType: "jsonp",
data: {amount: '1.00'},
success: function(response) {

if (response.success) {

inrv = parseFloat(response.rate).toFixed(2);

}
else {
alert('error response : '+response);
}


}
});

$.ajax({

url: 'https://currency-api.appspot.com/api/USD/JPY.jsonp',
dataType: "jsonp",
data: {amount: '1.00'},
success: function(response) {

if (response.success) {

jpyv = parseFloat(response.rate).toFixed(2);

}
}
});

$.ajax({

url: 'https://currency-api.appspot.com/api/USD/RUB.jsonp',
dataType: "jsonp",
data: {amount: '1.00'},
success: function(response) {

if (response.success) {

rubv = parseFloat(response.rate).toFixed(2);

}
}
});

$.ajax({

url: 'https://currency-api.appspot.com/api/USD/GBP.jsonp',
dataType: "jsonp",
data: {amount: '1.00'},
success: function(response) {

if (response.success) {

gbpv = parseFloat(response.rate).toFixed(2);

}
}
});

function setValuesInTextFileds(){
document.getElementById('aud').value= audv;
document.getElementById('inr').value= inrv;
document.getElementById('jpy').value= jpyv;
document.getElementById('rub').value= rubv;
document.getElementById('gbp').value= gbpv;
}


$.mobile.loading().hide();

</script>
</head>
<body>

<div id='MasterContainer'>
<div id='HeaderDiv'>
<div style='float: left;'>
<a href='#' data-rel="back"><img src='../res/icon/Arrows-Back-icon.png' border='0' style='margin-top: 9px;' /></a></div><br/>
<label style='font-size: 20; margin:0 auto; display:table; vertical-align:middle;'>Show Rates</label>
</div><!-- HeaderDiv ends -->
<table border='0' class='tableclass'>
<col width='30%'>
<col width='30%'>
<col width='30%'>
<tr><th>Country Name</th><th>Currency Name</th><th>Value against USD</th></tr>
<tr><td align='center'>Australia</td><td align='center'>AUD</td><td><input type='number' name='aud' id='aud' class='enjoy-input textfieldclass' style='background: #E8E8E8; padding-left: 5px;' disabled></td></tr>
<tr><td align='center'>India</td><td align='center'>INR</td><td><input type='number' name='inr' id='inr' class='enjoy-input textfieldclass' style='background: #E8E8E8; padding-left: 5px;' disabled></td></tr>
<tr><td align='center'>Japan</td><td align='center'>JPY</td><td><input type='number' name='jpy' id='jpy' class='enjoy-input textfieldclass' style='background: #E8E8E8; padding-left: 5px;' disabled></td></tr>
<tr><td align='center'>Russia</td><td align='center'>RUB</td><td><input type='number' name='rub' id='rub' class='enjoy-input textfieldclass' style='background: #E8E8E8; padding-left: 5px;' disabled></td></tr>
<tr><td align='center'>UK</td><td align='center'>GBP</td><td><input type='number' name='gbp' id='gbp' class='enjoy-input textfieldclass' style='background: #E8E8E8; padding-left: 5px;' disabled></td></tr>
</table>
<table border='0' class='tableclass'>
<col width='30%'>
<col width='30%'>
<tr><td align='center'>
<div class='button' onclick='setValuesInTextFileds()' style='padding: 10px 20px;'>Get Online</div>
</td><td align='center'>
<div class='button' onclick='setLocalValues()' style='padding: 10px 20px;'>Get Saved</div>
</td></tr>
</table>
</div><!-- MasterContainer div ends-->
</body>
</html>

最佳答案

要让您的移动设备与其他网站通信,您必须将它们列入白名单。如果您不这样做,那么您的移动应用程序将无法与外界通信。 (在浏览器上测试时不需要白名单,但在移动设备上测试时始终需要)。

要将网站列入白名单,您必须:

  1. 修改您的 config.xml包括行 <access origin="*" />
  2. 通过 phonegap 构建或在本地作为 cordova 插件安装白名单插件。找到 cordova 插件 here .

可以找到有关此问题的更多信息 here .

这是 Phonegap 开发人员常犯的错误。 This文章列出了您可能制作的更多内容。

关于android - api在浏览器中工作但在android phonegap中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33730720/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com