Php 刷新时输入值未更改为其默认值
我正在使用谷歌货币转换器。一切正常,但在页面刷新时,我无法将输入值设置为其原始值。下面是我的代码Php 刷新时输入值未更改为其默认值,php,javascript,jquery,html,Php,Javascript,Jquery,Html,我正在使用谷歌货币转换器。一切正常,但在页面刷新时,我无法将输入值设置为其原始值。下面是我的代码 <script src = "js/CurrencyConverter.js" type="text/javascript"></script> <select id="FromCurrency" class="CurrencyDropDown"></select> <input type = "text" id = "UnitP
<script src = "js/CurrencyConverter.js" type="text/javascript"></script>
<select id="FromCurrency" class="CurrencyDropDown"></select>
<input type = "text" id = "UnitPrice" value="enter amount"/>
</br>
<select id="ToCurrency" class = "CurrencyDropDown"></select>
<input type = "text" id = "destinationPrice" value="result"/>
<script>
$(document).ready(function(){
$('select#ToCurrency').change(function(){
convertcurrency();
})
});
function convertcurrency(){
var url = $('input[type=hidden]').val();
var priceunit = $('input#UnitPrice').val();// alert(priceunit);
var fromcurrencycode = $('select#FromCurrency').val(); //alert(fromcurrencycode);
var tocurrencycode = $('select#ToCurrency').val();// alert(tocurrencycode);
ConvertCurrency(url, priceunit,fromcurrencycode,tocurrencycode);
}
function ConvertCurrency(Url , PriceUnit,fromCurrencyCode,toCurrencyCode){
$.ajax({
url: '<?php echo site_url('curchange')?>',
type : 'POST',
dataType: "html",
data : {unitprice : PriceUnit, fromcode : fromCurrencyCode, tocode : toCurrencyCode},
success: function (data) {
if(data != '')
$('input#destinationPrice').val(data);
else
alert('Cannot convert');
},
error : function(){
alert('Error in Loading Data');
}
});
return false;
}
</script>
在CurrencyConverter.js中,我列出了窗口加载时加载到下拉列表中的国家/地区
curchange.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Class Curchange extends CI_Controller{
function __construct() {
parent::__construct();
}
function index(){
$unit = $this->input->post('unitprice');
$from = $this->input->post('fromcode');
$to = $this->input->post('tocode');
$url = 'http://www.google.com/ig/calculator?hl=en&q='.$unit.$from.'=?'.$to;
$ch = curl_init();
$timeout = 0;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$rawdata = curl_exec($ch);
curl_close($ch);
$data = explode('"', $rawdata);
$error = explode(' ', $data[5]);
if(empty($error[0])){
$data = explode(' ', $data[3]);
$var = round($data[0], 3);
}else{
$var = '';
}
echo $var;
}
}
?>
代码运行正常。正在转换货币,但当我更改货币,然后刷新页面,而不是将输入值显示为“输入金额”和“结果”时,输入html标记将显示初始值。为什么
欢迎提供任何帮助/建议。在$document.readyfunction后面写两条语句{ 比如:
它将在页面刷新时设置默认值simple call convertcurrency;此函数在第一次页面加载时使用…或点击ctr+F5清除缓存问题已解决,但据我所知,在页面刷新时输入标记必须设置默认值,不是吗?@sammy Dipesh Parmar已经描述了问题,值是从Brown获取的ser的缓存您是对的,但目前我无法测试脚本的时间限制。
$(document).ready(function(){
$("#UnitPrice").val("enter amount");
$("#destinationPrice").val("result");
});