Welcome Guest, Not a member yet? Register   Sign In
CSRF + ajax/jquery problem
#1

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.
Reply


Messages In This Thread
CSRF + ajax/jquery problem - by fedde - 09-08-2017, 09:58 AM
RE: CSRF + ajax/jquery problem - by dave friend - 09-08-2017, 02:44 PM
RE: CSRF + ajax/jquery problem - by fedde - 09-08-2017, 10:53 PM



Theme © iAndrew 2016 - Forum software by © MyBB