weixin_33671935 2017-08-20 01:19 采纳率: 0%
浏览 31

AJAX只工作一次

I did a modal with a login form and the submit through a POST AJAX request. I only can login one time, when I logout and try to login again the error message of AJAX request is this (CSRF failed):

Prohibido (403)
Verificación CSRF fallida. Solicitud abortada

The login only works again if I refresh the whole page pressing F5. After the success on the login I refresh only the header, not the whole page. My refresh code is this:

$('#update-' + idToUpdate).load(' #' + idToUpdate);

EDIT: I discovered that the CSRF token only works one time after a success request. I have to generate a new token for the form to work again, and this token only get update if I refresh the whole page pressing F5, and that is just what I do not want to do.

Any solution for this problem? I would not like to do AJAX requests to update the CSRF token, that is not secure.

  • 写回答

2条回答 默认 最新

  • weixin_33709609 2017-08-20 14:37
    关注

    I found a solution. Insert all the ids of the forms with the CSRF token in my function $('#update-' + idToUpdate).load(' #' + idToUpdate); after the success request. This do a partial async F5 refresh of the forms, so all the CSRF tokens get update and I can do new requests.

    评论

报告相同问题?

悬赏问题

  • ¥15 filenotfounderror:文件是存在的,权限也给了,但还一直报错
  • ¥15 关于远程桌面的鼠标位置转换
  • ¥15 MATLAB和mosek的求解问题
  • ¥20 修改中兴光猫sn的时候提示失败
  • ¥15 java大作业爬取网页
  • ¥15 怎么获取欧易的btc永续合约和交割合约的5m级的历史数据用来回测套利策略?
  • ¥15 有没有办法利用libusb读取usb设备数据
  • ¥15 为什么openeluer里面按不了python3呢?
  • ¥15 关于#matlab#的问题:训练序列与输入层维度不一样
  • ¥15 关于Ubuntu20.04.3LTS遇到的问题:在安装完CUDA驱动后,电脑会进入卡死的情况,但可以通过键盘按键进入安全重启,但重启完又会进入该情况!