Skip to content
Advertisement

Codeigniter CSRF valid for only one time ajax request

I want to upload image on the server on change event of jQuery but using codeigniter csrf I am able to upload image only one time. How can I upload images using ajax for multiple requests.Please keep in mind when I set this

JavaScript

then I am able to send multiple request jQuery onchange event but when csrf_protection is going to be false then I think there is no advantage of csrf. so the question is how can I send multiple requests using ajax while csrf_protection is enable. My jquery code is following

JavaScript

Advertisement

Answer

In my opinion you should try to recreate your csrf token each request

Try this code example…

For the js funcion

JavaScript

and for the controller

JavaScript

Let me know and good luck

Note: When someone ask you for posting more data to the question, don’t post it as a comment or answer, it’s better to edit the question itself and adding the stuff

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement