search input and csrf token desynchronization

search input and csrf token desynchronization

johndoojohndoo Posts: 18Questions: 5Answers: 1

I did not find a solution to this issue on the forum and I cannot post test case because this is a "random" issue, "most" of the time it works.
I use datatables with serverside enabled (data comes from a database).

When using search input of datatables and typing fast , this will cause multiple ajax calls to fire
and sometimes I obtain 403 errors from the serveur because a new ajax call is fired with the previous csrf token (and before the previous ajax call is terminated , so I cannot retrieve the last valid csrf token returned by the server).

Is there a way (in prexhr event ?) to prevent the next ajax call to fire if I detect that csrf token did not change ?

Or can I ignore typed chars in the search input until the previous ajax call has returned the data ?

Answers

  • kthorngrenkthorngren Posts: 20,302Questions: 26Answers: 4,769

    The searchDelay option may help. Or you can try the debounce solution from the thread.

    Kevin

  • johndoojohndoo Posts: 18Questions: 5Answers: 1

    Thanks a lot ! The Debounce() solution seems to work ! (I have to perform more testing to be sure because sometimes everything worked fine before)

  • johndoojohndoo Posts: 18Questions: 5Answers: 1

    I have done more testing , the default search input seems ok.
    I have then added some code to the Debounce() solution to handle an input filter per column (to be able to search only on one column).
    It works most of the time but in rare occasions I still have a 403 error due to csrf token.
    The main difference is that when it occurs I can continue to use the search without refreshing the page (before once a 403 occured, any new search produced a 403).

    So it is a good solution for the main search input, but not perfect when adding more search options.

This discussion has been closed.