Greeting StackOverflow! I am trying to pass data to controller using AJAX, but for some reasons it doesn\'t.
Controller:
public function updateSocial
function updateSocial(name){
var address = $("#" + name).val();
var key = name +"&&"+ address;
//alert(key);
$.ajax({
type: "GET",
url: "controller/updatesocial/"+key,
dataType: "text",
cache:false,
success:
function(data){
alert(data); //as a debugging message.
}
});
}
You are sending data using GET method so you have to send it by appending url and your controller will be
public function updateSocial(){
$key = $this->uri_segment(3);
if($key != null){
list($name, $address) = explode("&&", $key);
$this->db->query("UPDATE social SET address = '" . $address . "' WHERE name = '" . $name . "'");
echo "Affected rows: " . $this->db->affected_rows();
}
}