I'm trying to pass a json object from an ajax call in a variable that will be used in another function.
The thing is that if i try to console.log() that variable ($aR), it returns "undefined"
Here is the code:
$aR = '';
// Submit Data to ncbi.
// Sends form's data to classController.php
function NCBI_submit_data()
{
$formData = $('#blastx_form').serialize();
$php_method = 'ncbi_request';
$finalData = $formData + "&php_method=" + $php_method;
$aR = ajaxReq('POST','../../classes/classController.php',$finalData,'json');
console.log($aR);
}
// General Ajax function
function ajaxReq($method,$url,$data,$dataType)
{
$.ajax({
type: $method,
url: $url,
async: 'false',
data: $data,
dataType: $dataType,
success: function(json, textStatus, jqXHR)
{
$aR = json;
},
error: function(jqXHR, textStatus, errorThrown)
{
console.log('Ajax call error: '+jqXHR.status+' '+errorThrown)
}
});
}
$aRto the XHR object, then you're doing synchronous ajax and setting the same variable to the returned data, all the while thinking you're in PHP with novardeclarations but dollarsigns in front of all the variables instead ?