ajax di codeignitier muncul 500 (Internal Server Error)

Assalamualaikum,

Maaf temen-temen saya mau tanya, terakit proses ajax di codeignitier..

$(document).on('click','#submit-module', function(eve){
	    eve.preventDefault();
	    var action = $('#form-module').attr('action');
	    if(action=='#'){
	    	url = "<?php echo site_url('admin/module/input')?>";
	    }else{
	    	url = "<?php echo site_url('admin/module/update')?>";
	    }

	    //alert(save_action);
	    $.ajax({
	    	url:url,
	    	type: "POST",
        	data: $('#form-module').serialize(),
        	dataType: "JSON",
        	success:function(data)
        	{
        		alert(data.status);
        	}
	    });
  	});

Controller

public function action($param=''){
		global $SConfig;
		if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){
			if($param=='input'){
				$rules = $this->Module_model->rules;
				$this->form_validation->set_rules($rules);
				if($this->form_validation->run() == TRUE){
					$post = $this->input->post();
					$modules_sort = $this->Module_model->count();

					$data = array(
						'modules_name' => xss_clean($post['modules_name']),
						'modules_directory' => $post['modules_directory'],
						'modules_link' => $post['modules_link'],
						'modules_parent' => $post['modules_parent'],
						'class' => $post['class'],
						'i_icon' => $post['i_icon'],
						's_icon' =>$post['s_icon'],
						'view' =>$post['view'],
						'input' =>$post['input'],
						'update' =>$post['update'],
						'delete' =>$post['delete'],
						'download' =>$post['download'],
						'upload' =>$post['upload'],
						'description' =>$post['description'],
						'date_saved' =>$post['date_saved'],
						'modules_sort' =>$modules_sort,
						'active' =>$post['active']
					);

					if($this->Module_model->insert($data)){
						$result = array('status' => 'success');
					}
					else{
						$result = array('status' => 'failed');
					}
				}else{
					$result = array('status' => 'failed', 'errors' => $this->form_validation->error_array());
				}

				echo json_encode($result);
			}
		}

	}

avatar irfanmyj
@irfanmyj

32 Kontribusi 0 Poin

Diperbarui 6 tahun yang lalu

2 Jawaban:

Coba ikutin ini gan: (isinya disesuaikan)

In AJAX

 $(function(){
    $( "#submit_enquiry" ).click(function(event)
        {
            event.preventDefault();

        var date= $("#date").val();
        var candidate_id= $("#candidate_id").val();
        var user_id= $("#user_id").val();
        var req_id= $("#req_id").val();
        var status_type_id= $("#status_type_id").val();
        var interview_type_id= $("#interview_type_id").val();

        $.ajax(
        {
            type: "post",
            url: "<?php echo base_url(); ?>index.php/candidate/candidate_process",
            data:{
                'date':date,
                'candidate_id':candidate_id,
                'user_id':user_id,
                'req_id':req_id,
                'status_type_id':status_type_id,
                'interview_type_id':interview_type_id
            },
            //dataType: 'JSON',
            success:function(data)
            {
                console.log(data);
            }
        });
    });
});

In CONTROLLER

 public function candidate_process()
{
    # to check all inputs are comming.
    print_r($_POST);
}

source: https://stackoverflow.com/questions/42578149/500-internal-server-error-in-ajax-in-codeigniter/42621049#42621049

avatar keccikun
@keccikun

368 Kontribusi 197 Poin

Dipost 6 tahun yang lalu

Baik gan terimakasih banyak ya...

avatar irfanmyj
@irfanmyj

32 Kontribusi 0 Poin

Dipost 6 tahun yang lalu

Login untuk ikut Jawaban