How to avoid “The action you have requested is not allowed” error with Knockout postJson function call

核能气质少年 提交于 2020-01-05 04:31:08

问题


CodeIgniter gives an error "The action you have requested is not allowed." when it fails the check for CSRF. As I understand it, this means the POST is missing the hidden token from the form that proves that an attack is not being done.

The token is generated automatically with a call to the CI form_open function.

In my case, I'm using Knockout to post the contents of a ViewModel for saving, like this:

ko.utils.postJson($("form")[0], self.pages);

I've found solutions elsewhere that simply turn off the CSRF setting for the specific page, but that doesn't seem like a good solution.

Presumably because the token is not being received, the postJson call is not submitting the existing form. Is there a way to either submit the required token along with the JSON data or submit the JSON data with the existing form?


回答1:


try to use form_open() and form_close

all form helper functions that will help.

or: I think it's from time zone difference as the Security class depends on time for hashing.



来源:https://stackoverflow.com/questions/13924740/how-to-avoid-the-action-you-have-requested-is-not-allowed-error-with-knockout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!