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

I really have tried several ways to send post data via ajax. CSRF is blocking me and I dont want to disable or exclude the controller from CSRF check.

Way One:

Code:
function sendrow(e){
var working=$('#working');
var value="<?php echo $this->security->get_csrf_hash();?>";
var name="<?php echo $this->security->get_csrf_token_name(); ?>";
working.html('');
var path='http://localhost/ph/ctrl/process';
working.html('<img src="http://localhost/ph/assets/img/loading24.gif/>"').load(path, {name:value,'e':e}, function(data, status, response) {
                                                                                                                                                
            working.html("");    
                    if(status!='error'){
                        alert(true);
                        
                    }
                        else {
                            alert('server error');
                        }
            
            
                });
}

Method Two:

Code:
function sendrow(e){

$.ajax({
            type: "post",
            async: true,
            url: path,
            data: {name:value,'e':e},
            contentType: "application/json; charset=utf-8",
            dataType: "text",
            success: function (msg) {
            alert(true);
              
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert('server error');
            }
        });

}

I have tried opening form with open_form then serialize it in javascript but failed too. What am I missing exactly? The CSRF data (name and value) is set correctly. Every method I saw online didnt work too. If I change the method to "get" oriented method in my controller, it works fine but it must be posted.

Any clues?
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