title: how to insert from data using ajax in codeigniter?
body: <p><strong>controller: test.php</strong></p>
  <pre><code>public function signin()
  {
      if($this-&gt;input-&gt;post('insert'))
      {
          $name = trim($this-&gt;input-&gt;post('name'));
          $email = trim($this-&gt;input-&gt;post('email'));
          $phone = trim($this-&gt;input-&gt;post('phone'));
          $message = trim($this-&gt;input-&gt;post('message'));
          $s_data = date('Y-m-d');
  
          $data = array(
                      'name' =&gt; $name,
                      'email' =&gt; $email,
                      'phone' =&gt; $phone,
                      'message' =&gt; $message,
                      's_date' =&gt; $s_date
                      ); 
  
          $recaptchaResponse = trim($this-&gt;input-&gt;post('g-recaptcha-response'));
          $userIp=$this-&gt;input-&gt;ip_address();
          $secret='****************************';
          $url=&quot;https://www.google.com/recaptcha/api/siteverify?secret=&quot;.$secret.&quot;&amp;response;=&quot;.$recaptchaResponse.&quot;&amp;remoteip;=&quot;.$userIp;
          $response = $this-&gt;curl-&gt;simple_get($url);
          $status= json_decode($response, true);
  
          $this-&gt;db-&gt;insert('contact',$data);
          if($status['success'])
          {     
              $this-&gt;session-&gt;set_flashdata('flashSuccess', 'successfull');
          }
          else
          {
              $this-&gt;session-&gt;set_flashdata('flashSuccess', 'Sorry Google Recaptcha Unsuccessful!!');
          }
      }
  }
  </code></pre>
  <p><strong>Ajax Code:</strong></p>
  <pre><code>&lt;script&gt;
      $(document).ready(function(){
          $(&quot;#insert&quot;).click(function(){
              var name = $(&quot;#name&quot;).val();
              var email = $(&quot;#email&quot;).val();
              var phone = $(&quot;#phone&quot;).val();
              var message = $(&quot;#message&quot;).val();
              var dataString = 'name='+ name + '&amp;email='+ email + '&amp;phone='+ phone + '&amp;message='+ message;
              if(name==''||email==''||phone==''||message=='')
              {
                  alert(&quot;Please Fill All Fields&quot;);
              }
              else
              {
                  // AJAX Code To Submit Form.
                  $.ajax({
                      type: &quot;POST&quot;,
                      url: &quot;&lt;?php echo base_url('index.php/'); ?&gt;test/signin&quot;,
                      data: dataString,
                      cache: false,
                      success: function(result){
                          alert(result);
                      }
                  });
              }
              return false;
          });
      });
  &lt;/script&gt;
  </code></pre>
  <p><strong>Bootstrap Modal View Code:-</strong></p>
  <pre><code>&lt;div class=&quot;modal fade&quot; id=&quot;myModal&quot; tabindex=&quot;-1&quot; role=&quot;dialog&quot; aria-labelledby=&quot;myModalLabel&quot; aria-hidden=&quot;true&quot;&gt;
      &lt;div class=&quot;modal-dialog&quot;&gt;
          &lt;div class=&quot;modal-content&quot;&gt;
              &lt;div class=&quot;modal-header&quot;&gt;
                  &lt;button type=&quot;button&quot; class=&quot;close&quot; data-dismiss=&quot;modal&quot; aria-label=&quot;Close&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;&amp;times;&lt;/span&gt;
                  &lt;/button&gt;
                   &lt;h4 class=&quot;modal-title&quot; id=&quot;myModalLabel&quot;&gt;header&lt;/h4&gt;
              &lt;/div&gt;
              &lt;div class=&quot;modal-body&quot;&gt;
                  &lt;div class=&quot;error&quot;&gt;&lt;strong&gt;&lt;?=$this-&gt;session-&gt;flashdata('flashSuccess')?&gt;&lt;/strong&gt;&lt;/div&gt;
                  &lt;form method=&quot;post&quot; enctype=&quot;multipart/form-data&quot; id=&quot;form1&quot;&gt;
                      &lt;input type=&quot;text&quot; class=&quot;form-control1&quot; id=&quot;name&quot; name=&quot;name&quot; placeholder=&quot;Enter Your Name&quot;&gt;
                  
                      &lt;input type=&quot;text&quot; class=&quot;form-control1&quot; id=&quot;email&quot; name=&quot;email&quot; placeholder=&quot;Enter Your Email Id&quot;&gt;
              
                      &lt;input type=&quot;text&quot; class=&quot;form-control1&quot; id=&quot;phone&quot; name=&quot;phone&quot; placeholder=&quot;Enter Your Phone&quot;&gt;
              
                      &lt;textarea class=&quot;form-control1&quot; name=&quot;message&quot; id=&quot;message&quot;  placeholder=&quot;Enter Your Message&quot;&gt;&lt;/textarea&gt;
  
                      &lt;div class=&quot;g-recaptcha&quot; data-sitekey=&quot;****************************&quot;&gt;&lt;/div&gt;                   
                      &lt;/br&gt;
                      &lt;input type=&quot;submit&quot; name=&quot;insert&quot; id=&quot;insert&quot; value=&quot;Submit&quot;&gt;
                  &lt;/form&gt;
                  
              &lt;/div&gt;
              &lt;div class=&quot;modal-footer&quot; style=&quot;background: #2874f0;padding: 25px;&quot;&gt;
                  &lt;p&gt;footer&lt;/p&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  <p>In this code, I have create a <code>bootstrap modal</code> which is open when page is load and inside modal body I have create a simple enquiry from with Google recaptch. Now, I want to insert form data using ajax without loading page after inserting value into database it show successfull message.</p>
  <p>So, How can I do this ?Please help me.</p>
  <p>Thank You</p>