php - Getting empty data in AJAX after POST -
i'm building trading system , i'm using php data, when arrives empty. it's first time use ajax , don't know doing wrong. here code:
script:
$(document).ready(function() { $('#submit').click(function(){ //get values var amount = $('#amount').val(); var = $('#from').val(); var = $('#to').val(); var params = 'select * yahoo.finance.xchange pair in ("' + + +'")'; console.log( params ); $.ajax({ type: "post", url: "currencies.php", data: params, success: function(data){ $('#result').html(data); alert(data); //i'm alerting because not receiving nothing @ #result } }); }); }); php:
$base_url = "http://query.yahooapis.com/v1/public/yql"; $yql_query = $_request['params']; $yql_query_url = $base_url . "?q=" . urlencode($yql_query) . "&format=json" . "&env=http://datatables.org/alltables.env"; $session = curl_init($yql_query_url); curl_setopt($session2, curlopt_returntransfer,true); $json = curl_exec($session); $phpobj = json_decode($json); $conversiones = $phpobj->query->results->rate; $title = new arrayobject(); $title = "$conversiones->name"; echo $title; i typed:
params=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20("mxnusd") in url, see if php file working , is. echoes name of currencies, not received in script.
thanks in advance.
edit: fixed typos.
you need send key/value pair. sending value without params key.
the key using in php $_request['params']
look in browser console network tab , won't see same url manually put in address bar
try
$.ajax({ type: "post", url: "currencies.php", data: {params: params}, // object key/value success: function(data){ $('#result').html(data); alert(data); } }); also note can print json without echo in php. otherwise json parse error in ajax
just fyi - can make same request directly yahoo right browser without proxy in php on server. see yql console
Comments
Post a Comment