Ajax POSt not working in IE11

5

I have a button in my webpage which calls an ajax method a s below

    $.ajax({
        cache: false,
        type:'POST',
        data: 'type='+userType +'&user='+user ,
        url:' ".\yii\helpers\Url::to([$program.'/'.$url.'/setcustomer/'])."     ', 
        success: function(data) {
            console.log('Hii');
            $('#phoneErr').html(data);                            
        }
    });

This works in all browsers except IE11 I get the following error when i click on the button:

SCRIPT7002: XMLHttpRequest: Network Error 0x800c0008, The download of the    specified resource has failed.

Has anyone faced this issue and what is the solution to this?

There is a redirection in my PHP code in the setcustomer action. Can this issue be related to it?

My ajax response body says Key Value Response HTTP/1.1 302 Found and not actually redirecting to the required page is the problem related to IE ajax cannot handle 302 redirect within an ajax response as success.

ajax
redirect
yii2
internet-explorer-11
asked on Stack Overflow Oct 6, 2015 by Vimla S. Naik • edited Oct 6, 2015 by Vimla S. Naik

1 Answer

0

I make the next solution:

in js:

$(document).ajaxComplete(function (event, xhr, settings) {
    var url = xhr && xhr.getResponseHeader('X-Redirect');
    if (url) {
        window.location = url;
    }
});

in php (yii2) (ie not understand 302 via ajax, we send 200) :

$this->redirect(['index', 'id' => $model->id], 200);

User contributions licensed under CC BY-SA 3.0