netpumber Posted July 8, 2014 Share Posted July 8, 2014 Hi! I have this code above: // 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) { return json; }, error: function(jqXHR, textStatus, errorThrown) { console.log('Ajax call error: '+jqXHR.status+' '+errorThrown) } }); } Server returns a json object and i want to save it in aR variable. But console.log($aR); returns undefined Any idea on how to fix it ? Quote Link to comment Share on other sites More sharing options...
fastsol Posted July 8, 2014 Share Posted July 8, 2014 Wouldn't this line return json; Just turn into this var aR = json; Quote Link to comment Share on other sites More sharing options...
netpumber Posted July 8, 2014 Author Share Posted July 8, 2014 Hmm i created a global var $aR = ''; then in the // 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) } }); } But doesn't seem to work. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.