zaib fridi
zaib fridi

Reputation: 19

Ajax success return value use in other function

On file upload, I want ajax hit the url like:

$.ajax(
    { url: '<?php echo base_url();?>apk-reader/ApkInfo.php',
      data: {"apps": "../apps/apk_files/"+file, user_id: "<?php echo $this->session->userdata('user_id'); ?>"},
      type: 'get',
      success: function(output) { alert(output);}

Here I want to store the out put in another variable and use it in OnComplete of another ajax load.

Upvotes: 2

Views: 2028

Answers (3)

Sirwan Afifi
Sirwan Afifi

Reputation: 10824

you can use this code :

$.ajax({
      url: 'your URL',
      data: {"your Parameter"},
       type: 'get',
      success: function(data) { 
           AjaxMethode(data)
       }
  });

function AjaxMethode(data){
    if(data.d){
        //someCode
    }
}

Upvotes: 0

Adil
Adil

Reputation: 148120

Call other function from success and pass the result to it, SomeFunction(output);

$.ajax({
      url: '<?php echo base_url();?>apk-reader/ApkInfo.php',
      data: {"apps": "../apps/apk_files/"+file, user_id: "<?php echo $this->session->userdata('user_id'); ?>"},
       type: 'get',
      success: function(output) { 
           alert(output);SomeFunction(output)
       }
  });

Upvotes: 1

Vivek S
Vivek S

Reputation: 5540

Declare a variable in global scope and store your output in that varibale. Now you can access the global variable at the callback of any other ajax method,

var result1;
$.ajax( { url: 'apk-reader/ApkInfo.php', data: {"apps": "../apps/apk_files/"+file, user_id: "session->userdata('user_id'); ?>"}, type: 'get', success: function(output) { alert(output);
result1=output;
}
$.ajax( { url: 'apk-reader2/ApkInfo.php', data: {"apps": "../apps/apk_files/"+file, user_id: "session->userdata('user_id'); ?>"}, type: 'get', success: function(output2) { alert(output2);
alert(result1);

}

Upvotes: 0

Related Questions