Gaurav Deshani
Gaurav Deshani

Reputation: 11

how to get Ajax Success Function data in codeigniter

my ajax code

$.ajax({
          url : '<?php echo base_url('mobile_plan/getStates')?>',
          type: 'POST',
          data:{operator:operator},
          dataType:'json',
          success: function(response)
          {
              alert(response);
          }
       });

I am getting response in array for from controller now this ajax call is done from the same page in which I want response back in PHP array for further operating could you please guide me how it is possible. I am using codeigniter 3.1.

Upvotes: 0

Views: 1070

Answers (2)

amir ali
amir ali

Reputation: 111

If you want to send this response again to the controller in php you should create another ajax call with POST method and pass the response array as a data parameter.

Upvotes: 2

nico263nico
nico263nico

Reputation: 151

When using ajax it's recommended to pass data in JSON format.

In PHP you should do

echo json_endoce($data);

And in Javascript, in your success function

response = JSON.parse(response);

Upvotes: 0

Related Questions