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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵