this is my ajax code and im using Codeigniter framework, and im trying to send data to the controller
<script>
$('#mssgg').submit(function(){
var ms = $('#mess').val();
$.ajax({
type:'POST',
url:'http://localhost/index.php/C_Main_page/store_chat',
data:'messege'+ms,
error:function(data){
alert("error");
},
success:function(data){
alert("success");
}
});
});
</script>
i keep getting error, what did i do wrong??
data:'messege'+ms,
.This: data:'messege'+ms,
either should be data:'messege='+ms,
or better one as an object data:{messege:ms},
.
<script>
$('#mssgg').submit(function(e){
e.preventDefault(); // <----stop the form submission.
var ms = {messege : $('#mess').val() }; //<----create an object
$.ajax({
type:'POST',
url:'http://localhost/index.php/C_Main_page/store_chat',
data:ms, //<----and pass that object here.
error:function(data){
alert("error");
},
success:function(data){
alert("success");
}
});
});
</script>