• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ajax post csrf problem 403 error

#1
Hello everyone

I know this topic got discussed many time .. yet I could not make it run without problems

first of all .. I set csrf to true

PHP Code:
$config['csrf_protection'] = TRUE;  


now I included csrf token/value in the data sent by ajax
and it works for the first time ( as csrf is present and it is correct )
in the second time ajax tries to run .. I get 403 error ( as the sent csrf is still the same not changed ( not refreshed page ) )
i found that the first post will change the token value of csrf

how should I work with that and make it run ?

here is my code ( note that Iam using smary )

PHP

PHP Code:
        $this->vars['csrf'] = array(
        'name' => $this->security->get_csrf_token_name(),
        'hash' => $this->security->get_csrf_hash()
        ); 


HTML

Code:
<input type="text" class="form-control" name=atitle id=atitle>
<input id=csrf name="{$csrf.name}" type="hidden" value="{$csrf.hash}" />
<script>
$("#atitle").on('input propertychange paste change',function () {
    $.post("{$baseurl}Ajax/ar2eng",{ {$csrf.name}: $("#csrf").val(),title: $("#atitle").val() }).done(function( data ) {
     $("#aslug").val(data);
    });
  });
</script>
Reply


Messages In This Thread
ajax post csrf problem 403 error - by arabgenius - 04-16-2017, 02:42 PM
RE: ajax post csrf problem 403 error - by PaulD - 04-17-2017, 02:31 AM
RE: ajax post csrf problem 403 error - by PaulD - 04-17-2017, 03:29 AM
RE: ajax post csrf problem 403 error - by PaulD - 04-17-2017, 05:46 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.