私のjqueryコードは以下のとおりです。これはAPIを介して変換する通貨です。jsonのAPIデータで。AJaxでデータを取得したい。
Im geting the error : Fatal error: Cannot access empty property in C:\xampp\htdocs\mvc\converter\ajax.php on line 25
<script type="text/javascript">
$(document).ready(function(){
$("#currency").change(function(){
var currency= $("#currency").val();
$.ajax({
type: "GET",
url: "ajax.php",
cache: false,
data: currency,
dataType: "text",
success: function(data){
alert(data);
$("#quantity").keyup(function(){
//var local_rate= $("#local_rate").val();
var quantity= $("#quantity").val();
var us_rate= quantity / cur;
$('.listprice').html(us_rate);
});
}
});
});
});
</script>
これが私のphp(ajax.php)コードです
<?php
$currency =$_GET['currency'];
$file = 'latest.json';
$appId = '306bdd0f71fe465280e48188846534af';
// Open CURL session:
$ch = curl_init("http://openexchangerates.org/api/{$file}?app_id={$appId}");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Get the data:
$json = curl_exec($ch);
curl_close($ch);
$exchangeRates = json_decode($json);
echo $rate= $exchangeRates->rates->$currency;
?>
jqueryを使用せずにデータを取得することに固執しましたが、完全に機能しています...ここでは、Ajaxを介してロードしたいと思います。