我正在尝试使用以下API获取实时汇率。
"http://www.exchangerate-api.com/INR/USD/1?k=FQRxs-xT2tk-NExQj"
当我单击一个按钮时,它会提示速率并正常工作。我正在使用以下Ajax代码。
function testCurrencyRate()
{
$.ajax({
datatype:"html",
type: "GET",
url: "ajax/LiveCurrencyRate.php",
data: "t="+new Date().getTime(),
success: function(response)
{
alert(response);
},
error: function(e)
{
alert('Error while fetchig the live currency rate.');
}
});
}
Ajax请求转到以下LiveCurrencyRate.php页面。
$url="http://www.exchangerate-api.com/INR/USD/1?k=FQRxs-xT2tk-NExQj";
$result = file_get_contents($url);
echo $result;
,
其中包含唯一的按钮,当单击该按钮时,将对此URL发出Ajax请求ajax/LiveCurrencyRate.php。一切都很好。但是,当我将按钮类型从更改为时,问题就出现type="button"了type="submit",它不起作用。Ajax函数的错误部分中的
警报框只显示了一段时间,然后突然消失了
。我找不到任何可能导致无法完成此请求的合理原因。在上一个项目中,同样的事情对我有用,但是我XMLHttpRequest用于发出Ajax请求。这是怎么了