Welcome Guest, Not a member yet? Register   Sign In
Ajax POST and CSRF
#2

This works fine to me:

Code:
<form method="post" id="some_form">
<?=form_hidden($this->security->get_csrf_token_name(), $this->security->get_csrf_hash())?>
<input name="some_input" />
</form>

and then

Code:
$(function(){
$("body").on("submit","#some_form",function(e){
e.preventDefault();
$.ajax({
url: $(this).attr("action"),
method: $(this).attr("method"),
data: $(this).serialize()
})
.done(function(data){
//something
})
.fail(function(){})
.always(function(){});
});
});

I hope it helps.
Reply


Messages In This Thread
Ajax POST and CSRF - by sammyci - 02-20-2016, 10:46 AM
RE: Ajax POST and CSRF - by ikarius6 - 02-20-2016, 03:38 PM
RE: Ajax POST and CSRF - by sammyci - 02-20-2016, 08:05 PM
RE: Ajax POST and CSRF - by mwhitney - 02-26-2016, 07:37 AM
RE: Ajax POST and CSRF - by ismaelirc - 07-11-2016, 12:35 PM



Theme © iAndrew 2016 - Forum software by © MyBB