-1

I am using Ajax to post my data, while using inspect elemet, I can see the post data from all other fields, but text area field comes empty, so the data fails to be saved to the database.

 function addblog() {

        save_method = 'add';

        url = "<?php echo site_url('index.php/blog/post_new_blog')?>";

        $.ajax({
             url: url,
             type: "POST",
             data: $('#addblog').serialize(),
             dataType: "json",
             success: function (data) {
                  alert('Saved');
             },
             error: function (jqXHR, textStatus, errorThrown) {
                    alert('Error adding / update data');
       }
   });
}

HTML:

    <div id="editor-one" class="editor-wrapper"></div>
    <textarea  id="descr" class="text" name="desc" style="display:none;"></textarea>

PHP:

    public function post_new_blog()
{
    $data = array(
        'blog_title' => $this->input->post('title', true),
        'blog_content' => $this->input->post('desc', true),
        'blog_tags' => $this->input->post('tags', true),
    );

    $insert = $this->main_model->save_new_posts($data);

    echo json_encode(array("status" => TRUE));
 }
ArK
  • 20,698
  • 67
  • 109
  • 136
Lexie
  • 7
  • 5

1 Answers1

0

You are sending data as follows:

data: $('#addblog').serialize(),

does your

<textarea  id="descr" class="text" name="desc" style="display:none;"></textarea>

inside html element with id addblog?

Meanwhile, i didn't understand why you set display to none for textarea?

yılmaz
  • 1,818
  • 13
  • 15