jackson jackson - 4 months ago 13
Ajax Question

Error in Ajax code to get response from codeigniter

i wrote many ajax request in my form but i don't know why one of my simple below code shows me error, i want to send my request to codeigniter to get response from my database:

$(document).ready(function(){

$('.confirm_send').on('click',function(){

var base = '<?php echo base_url(); ?>';

var confirm_send_id=$(this).attr('id');


$.ajax({
'url': base + 'my_site/confirm_send',
'type':'post',
'dataType':'json',
'data':{
'id':confirm_send_id
},
'success':function(){
alert("sucssess");},

'error':function(){
alert("Error");
}


});//end of ajax confirm send button

});//end of confirm send button

});//end of jquery

Answer

Try This:

 $('.confirm_send').on('click',function(){

     var base = '<?php echo base_url(); ?>';
     var confirm_send_id = $(this).attr('id');

     $.ajax({
        url: base + 'my_site/confirm_send',  //make sure it is a valid path
        type: 'POST',
        data:({'id':confirm_send_id}),
        success :  function(response){
             alert("Success");
        },

        error : function(response){
            alert("Error");
        }
    });//end of ajax confirm send button


});