Vimal
Vimal

Reputation: 1146

500 POST internal server error ajax

I just started to learn Ajax.I have situation in which when i call the ajax i have got this in my console.

POST http://server1/cmsgovtsite/admin/announcement/remove_attachment 500 (Internal Server Error)

I am using the codeigniter platform. I have referred to many solutions on Stack Overflow, but I haven't been able to solve this.

function remove(attachment_id) {                            
    var baseurl = $('#base').val();
    //alert(baseurl);
    //alert(attachment_id);

    $.ajax({
        url: baseurl + "admin/announcement/remove_attachment",
        // async: false,
        type: "POST",
        data: {
            attachment_id: attachment_id
        },
        datatype: "json",
        success: function(result) {
            $('#result1').html(result);
        }
    })
}
function remove_attachment() 
{
    // $this->new_announcement();
    // echo sdfsdfdfg;
    $id = $this->input->post('attachment_id');
    echo 'hello'.$id;
    $this->load->model('announcement_model');
    // $data['ajax_req'] = TRUE;
    $this->announcement_model->changestatus($id);
    // $this->load->view('announcement_edit',$data);
}
<button class="btn pull-right" type="button" onclick="remove(<?php echo $getannouncementfile['id'] ?>)">
    <i class="fa fa-minus-circle fa-1x" aria-hidden="true" title="Add more document" alt="Add more documents"/></i> 
    Remove Attachment
</button>

And i have to add that the error only happens when i load my model

Upvotes: 1

Views: 1300

Answers (4)

Vimal
Vimal

Reputation: 1146

I solved my issue by editing the controller function and not by calling the model. Now my controller is as follows

function remove_attachment() {

$id=$this->input->post('attachment_id');
$data=array(
            'status'    => '0',                                                                              );
$this->db->where('id',$id);
$this->db->update('tb_announcements_file',$data);
 //echo'One record deleted Successfully';
 exit;

}

Thanks to everyone who had helped me..

Upvotes: 0

Md Safiul Alam
Md Safiul Alam

Reputation: 153

Check ensure your .htaccess or Change your url like below

url: baseurl + "index.php/admin/announcement/remove_attachment",

Upvotes: 2

Trushar Narodia
Trushar Narodia

Reputation: 366

try this code with mozilla firefox browser so in inspect panel you will get full details with request and response data and also get where you wrong in your code

check in your config file if csrf_protection is true then do it false and then try it

Upvotes: 0

cagri
cagri

Reputation: 828

Replace <?php echo $getannouncementfile['id'] ?> to <?php echo $getannouncementfile['id']; ?>

;

Upvotes: 0

Related Questions