Yii2 and Pjax redirect not working in Internet Explorer?
Asked Answered
F

1

7

I am using the framework Yii2 with their implementation of Pjax. The controller code adds a header "X-Pjax-Url" that is successfully passed with the response.

The redirect for Pjax is handled through the pjax.js methods just fine in Chrome, Safari, and Firefox, but fails in IE11.

When I use the included debugger and view the response headers, the header is there and the url is correct, but IE11 isn't reading it.

The response error: enter image description here

The response headers: enter image description here

Any ideas?

** Update 9/7/15

The controller code:

return $this->redirect(['secure/dashboard']);

Here is a link to the docs (yii\web\Controller) on how to use this method which is a shortcut to this (yii\web\Response) method.

Once again, this works in the Chrome, Safari, and Firefox, just not IE11.

I was using this snippet to verify the xhr response, which returns null.

// pjax complete
$(document).on('pjax:complete', function (event, xhr, textStatus, options) {
    alert(JSON.stringify(xhr));
    var url = xhr.getResponseHeader('X-Pjax-Url');
    if (url) {
        window.location = url;
    }
});

In the images above, you can see the header is actually being sent, it just seems as though IE is reading it properly.

The Pjax.js file actually handles the redirect, I was just using the snippet for debugging purposes.

Futilitarian answered 29/8, 2015 at 20:1 Comment(3)
give your code sampleZoochore
it would be helpful if you provide your code.Walli
Long shot, but we are chasing an XHR issue that is only broken in IE11 (and 10). In our situation, the read cuts off at the hyphen/dash. Started in the last few weeks. social.msdn.microsoft.com/Forums/en-US/…Partheniaparthenocarpy
S
2

I can verify this error. But i have no clue if this is an IE error or an yii2 error.

The only thing i know that the redirect works if I dont use "return" and render the normal view additionally to the redirect which does the pjax requests. e.g. i tested it in my index action which is displaying a grid with pjax enabled. Then i redirect on a pjax request (here a sort for a column) to the user view. (just as an example)

public function actionIndex()
{
    if (Yii::$app->getRequest()->getIsPjax()) {
        //return $this->redirect(['user/view','id'=>1]); // doesn't forword in IE.
        $this->redirect(['user/view','id'=>1]); // forwards also in IE.
    }

    $searchModel = new UserSearch();
    $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

    return $this->render('index', [
        'searchModel' => $searchModel,
        'dataProvider' => $dataProvider,
    ]);
}

Because the forward works if the normal view is rendered additionally I guess something is missing (most likely some headers). I would open an issue in the yii2 github and ask for support.

This was btw. the issue where the redirect together with pjax was changed https://github.com/yiisoft/yii2/issues/4395

edit: a quick fix would be to set status code 200 instead of default 302

if (Yii::$app->getRequest()->getIsPjax()) {
    return $this->redirect(['user/view','id'=>1], 200); // forwards also in IE.
}
Semiliterate answered 8/9, 2015 at 10:11 Comment(4)
I found out that if you are doing a redirect with status code 200 e.g. return $this->redirect(['user/view','id'=>1], 200); it works in IE as well. If you using the standard 302 it doesn't work in IE. One thing which can be made, that on Pjax requests the status code is set to 200 instead of 302 on redirects then it will work in IE as well. But you should open an issue in the yii2 github so this is checked by the dev's.Semiliterate
I never thought to try a different status code. Would the code change have other side effects?Futilitarian
I confirmed that the status code 200 does work. I will open an issue over there.Futilitarian
status code 200 is "ok" w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.1 where 302 which is the default on the redirect is "found" w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.3 i don't know if this would have some side effects on both codes normally a page is available. 302 is normally if a page is temporarily accessible under a different URI. This could be interesting for Search Providers like e.g. google. For an application it could be different if the app handles specific status codes differently e.g. in javascript.Semiliterate

© 2022 - 2024 — McMap. All rights reserved.