I have the following javascript code that takes a text from a text area and passes it over to a controller which then updates the database. The controller then gets the same text from the db using a model and passes it over to the javascript code to be displayed on a given div of the webpage without refreshing the page. The controller just works fine and returns the text after successful update to the db but my problem is, the ajax code does not post the same message on the given div, it returns the alert error. I dont know how to fix this, pliz help me.
<script type="text/javascript">
$(function() {
$('#submit').click(function() {
//get input data as a array
var post_data = {
'message': $("#message").val(),
'<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
};
$.ajax({
type: "POST",
url: "<?php echo base_url(); ?>index.php/fb/insertByajax",
data: post_data,
success: function(response) {
debugger;
// return success message to the id='result' position
$("#result").html(response);
},
error: function() {alert("oops..."); }
});
});
});
</script>