Php 如何在jquery中检索curl和Json值?

Php 如何在jquery中检索curl和Json值?,php,jquery,json,curl,Php,Jquery,Json,Curl,下面是我的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(){

下面是我的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>
Im获取错误:致命错误:无法访问第25行C:\xampp\htdocs\mvc\converter\ajax.php中的空属性
$(文档).ready(函数(){
$(“#货币”).change(函数(){
var currency=$(“#currency”).val();
$.ajax({
键入:“获取”,
url:“ajax.php”,
cache:false,
数据:货币,
数据类型:“文本”,
成功:功能(数据){
警报(数据);
$(“#数量”).keyup(函数(){
//var local_rate=$(“#local_rate”).val();
变量数量=$(“#数量”).val();
var us_比率=数量/电流;
$('.listprice').html(美元汇率);
});
}
});
});
});
下面是我的php(ajax.php)代码



我被困在检索数据上,没有使用jquery,它工作得很好。。。在这里,我想通过Ajax加载。

数据:货币,
更改为
数据:{currency:currency},
这样货币就可以通过
$\u GET['currency']

在不发出警报的情况下,如何将数据作为变量进行转换?
<?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;

?>