How Does Codeigniter Receive the Ajax Post Data in Controller

JQuery Ajax POST in Codeigniter

$(document).ready(function(){   

$("#send").click(function()
{
$.ajax({
type: "POST",
url: base_url + "chat/post_action",
data: {textbox: $("#textbox").val()},
dataType: "text",
cache:false,
success:
function(data){
alert(data); //as a debugging message.
}
});// you have missed this bracket
return false;
});
});

How does Codeigniter receive the ajax post data in controller

Change your ajax this:

$.ajax({
url : "<?php echo base_url(); ?>welcome/login"
type : "POST",
dataType : "json",
data : {"account" : account, "passwd" : passwd},
success : function(data) {
// do something
},
error : function(data) {
// do something
}
});

Change your controller this:

public function login() {
//$data = $this->input->post();
// now I can get account and passwd by array index
$account = $this->input->post('account');
$passwd = $this->input->post('passwd');
}

I hope this work for you...

send data from ajax to controller codeigniter

Try this. see if it works. Just using "type" instead of "method"

var day = $(obj).text();
var base_url = $('#baseurl').val();

$.ajax({
type: 'POST',
url: base_url + "Front_end_controller/eventi",
data: {date: day},
success:function(result) {
alert(result); // alert your date variable value here
},
error:function(result) {
console.log(result);
}
});

And in your controler :

public function eventi()
{
$day = $this->input->post('date');
if(!empty($day))
{
echo $day;
}
else
{
echo "No Data";
}
}

How to get data from controller to view using ajax in codeigniter

yes it will give you error when you use data type json. it means that on ajax call the data will be pass to controller in json format..
while you are passing a simple post data...

remove the datatype json. every thing is ok...

and more mistake use this line

url: "<?php echo base_url(); ?>/contorller_name/employee_master/"+id,


Related Topics



Leave a reply



Submit