Welcome Guest, Not a member yet? Register   Sign In
Ajax Question
#1

On my upload ajax I use Formdata but I would like to know how can I add / append the CSRF to it?

Code:
<?php echo $this->security->get_csrf_token_name(); ?>' : '<?php echo $this->security->get_csrf_hash(); ?>


Not sure where to put the secureity stuff on here

Code:
var formData = new FormData($(this).parent()[0]);
   formData.append('hash', $("#ask #input_hash").val());

Script

Code:
<script type="text/javascript">
$('#button-upload').on('click', function() {
    $('#form-upload').remove();
    
    $('body').prepend('<form enctype="multipart/form-data" id="form-upload" style="display: none;"><input type="file" name="file" /></form>');

    $('#form-upload input[name=\'file\']').trigger('click');
    
    $('#form-upload input[name=\'file\']').on('change', function() {
        var formData = new FormData($(this).parent()[0]);
           formData.append('hash', $("#ask #input_hash").val());

        $.ajax({
            url: "<?php echo base_url('questions/ask/upload');?>",
            type: 'post',        
            dataType: 'json',
            data: formData,
            cache: false,
            contentType: false,
            processData: false,        

            success: function(json) {
                if (json['success'])
                {
                    //alert('yes');
                }
            },
        });
    });
});    
</script>
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply


Messages In This Thread
Ajax Question - by wolfgang1983 - 07-01-2017, 04:28 AM
RE: Ajax Question - by PaulD - 07-01-2017, 05:29 AM
RE: Ajax Question - by wolfgang1983 - 07-01-2017, 05:46 AM
RE: Ajax Question - by PaulD - 07-01-2017, 07:07 AM



Theme © iAndrew 2016 - Forum software by © MyBB