yiisoft / jquery-pjax

pushState + ajax = pjax
http://pjax.herokuapp.com
MIT License
144 stars 40 forks source link

Check for duplicate secret parameter #15

Closed alex-code closed 9 years ago

alex-code commented 9 years ago

If pjax receives data as an array you can end up with duplicate secret parameters _pjax=#container

Can occur with a filter on a GridView.

cebe commented 9 years ago

can you explain a bit more how and why this can happen? and shouldn't we fix the cause then rather then working around it?

alex-code commented 9 years ago

Say you have a GridView with a filter wrapped with PJax.

When you change the GridView filter Pjax catches the form submit and appends _pjax to the querystring.

Now in your action where you render the GridView it sets the filterUrl to Yii::$app->request->url which now includes the _pjax param.

If you change the filter again the applyFilter function in yii.gridView.js parses the querystring in filterUrl when building the hidden form.

Pjax then serializes that form into an array and adds the _pjax parameter again.

SilverFire commented 9 years ago

Reproduced. The fix works fine

SilverFire commented 9 years ago

I think it's better to solve this problem on js side than touch PHP part of Yii

SilverFire commented 9 years ago

Merged https://github.com/yiisoft/jquery-pjax/commit/18a9183d578d81fb9dbb1c604daba48815c3ebd5

SilverFire commented 9 years ago

Thank you!