0

I have this jquery ajax function:

$.ajax({
    url: '/private_cloud/add_app/'+school_id+'/'+app_id,
    dataType: "json",
    async: false,
    success: function(data){
        if(data.status == 1)
        {
            console.log(data.status);
        }
    },
    error: function(error){
        alert("Error");
    }
});

When I am using chrome, and firefox, this is working perfectly fine. But when I am using internet explorer, it shows in the console "1" but the data wasn't even inserted in the Database.

This is my code in PHP:

public function add_app($school_id = NULL, $app_id = NULL)
{
    if($this->School->save($get_school))
    {
        echo '{"status":"1"}';
    }
    else{
        echo '{"status":"0"}';
    }

    die;
}
comebal
  • 946
  • 3
  • 14
  • 30
  • 1
    jqxhr actually has a "status" variable that is already used in ajax (though deprecated now) to indicate success of the xhr request - it is in fact still used, you should stay away from this and use something like "myStatus" to send to the jqxhr data object, not use "status" as your property name – sajawikio Aug 20 '13 at 07:25

1 Answers1

1

You haven't specified a request type so it's defaulting to GET therefore IE is (most probably) caching the response. Add

type: 'POST'

to your AJAX config object, eg

$.ajax({
    url: '/private_cloud/add_app/'+school_id+'/'+app_id,
    type: 'POST',
    // etc
Phil
  • 157,677
  • 23
  • 242
  • 245
  • although I thought using type: 'POST' is only for posting the data using .serialize() function. But anyways, it solved my problem. thanks again. – comebal Aug 20 '13 at 07:26