user3663 user3663 - 9 months ago 23
Ajax Question

500 internal server error in ajax in codeigniter

i am trying to post form values using ajax..but i got 500 internal error..

here is my ajax code:

$(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();
var url = "http://localhost/job_portal/index.php/Candidate/candidate_process" ;
$.ajax(
{
type:"POST",
// url: "<?php echo base_url(); ?>index.php/Candidate/candidate_process",
//url:"http://localhost/job_portal/index.php/Candidate/candidate_process" ,
url: url,
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);
}
});

});

});


Button code:

<button type="submit" id="submit_enquiry" name="submit" class="btn btn-primary">Schedule Next Round</button><br></br>


Can anyone help me..

Thanks in advance

Answer Source

Make sure <form> tag not defined with action= "" (shoud be empty)

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);
            }
        });
    });
});

Hence base_url() should be http://stackoverflow.com/ end / is required ...

In Controller

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

if above code shows all the data then, use the rest of codes