title: jquery ajax form submit not working with codeigniter but working otherwise
body: <p>I tried to submit a form using jquery ajax without codeigniter just to understand how ajax works. It worked fine but now I want to do it in codeigniter (since I am developing my application in CI). It's not inserting the values in the database. I do not know how to check where the problem is</p>
  
  <p>This is my form in view :-</p>
  
  <pre><code>&lt;form name="article_form" method="POST" action=""&gt;
   &lt;input type="text" name="title" placeholder="Title for your article" /&gt;
   &lt;br&gt;
   &lt;textarea rows="12" name="body" placeholder="Tell your story"&gt;&lt;/textarea&gt;
   &lt;br&gt;
   &lt;input type="submit" name="submit_article" id="submit_article" value="Post" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>This is my jquery ajax script :-</p>
  
  <pre><code>&lt;script language='JavaScript' type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js'&gt;&lt;/script&gt;
      &lt;script&gt;
          $('#submit_article').click(function(){
  
              var article_title = document.getElementById("title").value;
              var article_body = document.getElementById("body").value;
  
              $.ajax({
                  url: '&lt;?php echo base_url()."main/submit_article";?&gt;',
                  type: 'POST',
                  dataType: 'json',
                  data: 'title='+article_title + '&amp;body='+article_body,
                  success: function(output_string){
                      $('#result_table').append(output_string);
                  }
              });
          });
      &lt;/script&gt;
  </code></pre>
  
  <p>Main is the controller and this the function submit_article :-</p>
  
  <pre><code>public function submit_article()
  {
          $article_title = $this-&gt;input-&gt;post('title');
          $article_body = $this-&gt;input-&gt;post('body');
  
      $this-&gt;load-&gt;model("model_articles");
  
      if($this-&gt;model_articles-&gt;article_submit($article_title, $article_body))
      {
          return true;
      }
      else
      {
          return false;
      }
  }
  </code></pre>
  
  <p>This loads the model - model_articles and passes two value namely $article_title and $article_body to the function article_submit(). This is the function in the model that has to insert the values into the database :-</p>
  
  <pre><code>public function article_submit($article_title, $article_body)
      {
          $article_data = array(
              'title' =&gt; $article_title,
              'body' =&gt; $article_body
              );
  
          $query_insert_article = $this-&gt;db-&gt;insert('articles', $article_data);
          if($query_insert_article)
          {
              return true;
          }
          else
          {
              return false;
          }
      }
  </code></pre>