I am trying to create dynamic html created from jquery and save it as json and post to a database using codeigniter. Currently the data is not showing correctly in the database. its just 0. A few issues i am confused with. What should the values of the table be if its storing json data? varchar or what?
I using ajax to post from jquery to a controller in codeigniter
my code from jquery as below
$.ajax({
type: "POST",
dataType: "JSON",
//url: "<?php echo site_url('application/models/question_model/jsonAddData');?>",
url:'jsonAddData',
//data: cssObject,
data: item,
success: function(data) {
//alert('ok');
}
});
the controller code as below
if($this->input->is_ajax_request()) {
try{
$this->load->database();
$title = $this->input->post('cssObject');
print_r($title);
header('Content-Type: application/json',true);
$query1 = "INSERT INTO testjson (data) VALUES (".$this->db->escape($title).")";
$query = $this->db->query($query1);
log_message('debug',$title);
}
catch(Exception $e)
{
log_message('debug',$e->getMessage());
show_error($e->getMessage());
}
}
When i use chrome developer tools the post is ok. but in the database there is nothing. Thanks in advance for the help!