Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

ajax post csrf codeigniter

var csrfName = '<?php echo $this->security->get_csrf_token_name(); ?>',
    csrfHash = '<?php echo $this->security->get_csrf_hash(); ?>';
("#avatar").change(function(){
    var link = $("#avatar").val();

    var dataJson = { [csrfName]: csrfHash, id: "hello", link: link };

    $.ajax({
        url : "<?php echo base_url('main/test'); ?>",
        type: 'post',
        data: dataJson,            
        success : function(data)
        {   
            csrfName = data.csrfName;
            csrfHash = data.csrfHash;
            alert(data.message);
        }  
    });
});
Comment

ajax post csrf codeigniter

public function test() { 
    $config['upload_path'] = './uploads/'; 
    $config['allowed_types'] = 'gif|jpg|png'; 
    $config['max_size'] = 500; 
    $config['max_width'] = 260; 
    $config['max_height'] = 260; 

    $reponse = array(
                'csrfName' => $this->security->get_csrf_token_name(),
                'csrfHash' => $this->security->get_csrf_hash()
                )

    $this->load->library('upload', $config); 
    if (!$this->upload->do_upload('link')) { 
        $reponse['message'] = "error"; 
    } 
    else { 
        $data = array('upload_data' => $this->upload->data()); 
        $image_name = $data['upload_data']['file_name']; 
        $reponse['message'] = $image_name; 
    } 

    echo json_encode($reponse);
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: vscode jest disable auto run 
Javascript :: active class always appear in navlink 
Javascript :: Kendo grid Excel export with filter 
Javascript :: bash sort json alphabetically 
Javascript :: star looping javascript 
Javascript :: javascript how do I measure the time of the loop 
Javascript :: got bearer auth 
Javascript :: includes in javascript 
Javascript :: sequelize findall 2 attributes 
Javascript :: javascript in pdf 
Javascript :: javascript event listener get id of clicked items 
Javascript :: js addeventlistener keyup not working on phone 
Javascript :: ajax 
Javascript :: The element.appendChild() Method 
Javascript :: js add props to obj conditionally 
Javascript :: js number to string 
Javascript :: node express tutorial 
Javascript :: jquery creating several items 
Javascript :: regex match between quotes without escape 
Javascript :: select ng-options set default value 
Javascript :: d3.js click event 
Javascript :: stale element reference: element is not attached to the page document 
Javascript :: set VS Code SSH Remote shell to zsh 
Javascript :: setstate react 
Javascript :: preventing form from submitting 
Javascript :: javascript set value to the largest value in an array 
Javascript :: self-invoking function 
Javascript :: pie chart in javascript 
Javascript :: How do I access a class without an instance? +javascript 
Javascript :: react-particles-js not working 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =