Hi all
I got a little question about CSRF and ajax when enabling the $config['csrf_regenerate'] = TRUE; in the CI config. I have searched alot, tested diffrent solutions on stackexchange, found some here but nothing that does not give me a 403 after the first submission of the ajax.
I use form helper to create form, the csrf hidden field is inserted automatic.
My ajax code is
Code:
$('#testform').submit(function(e){
e.preventDefault();
$.ajax({
url: url_base+'csrftest/submit',
type:'post',
data:$('#testform').serialize(),
success:function(results){ //alert(results);
// Some code for refreshing stuff...
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
});
I have read about the jquery $.ajaxSetup but with no luck on getting it working when you use regeneration.
What is best practices and what solutions do you guys use when the page is not refreshed? Of course, disable the csrf regeneration all works as expected.
Thanks in advance.