title: How avoid offest problems by correctly sending multiple variables from ajax
body: <p>I am new in ajax.I want to send html form values along with some other variables  to php using ajax,so i serialize all input values and send to php.But the problem offset occurred, when i try to send multiple variables.</p>
  
  <p><a href="https://i.stack.imgur.com/B7V6m.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B7V6m.png" alt="enter image description here"></a></p>
  
  <pre><code>var_dump($_POST);
  array (size=2)
    'values' =&gt; string 'loanid=123&amp;loan_name=Bank+Loan&amp;description=FRB+Bank+Loan&amp;amount=25000&amp;textdatetimepicker1=27%2F01%2F2016&amp;rate=12.5' (length=114)
    'flag' =&gt; string '2' (length=1)
  </code></pre>
  
  <p>Here is my Ajax Code:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;                                             
                  $("form").on("submit", function( event ) {              
                      event.preventDefault();                 
                      var flag = 2;   //want to send this 
                      var values = $( this ).serialize();  //want to send this                        
                      $('#serialize').append(values);                  
                      $.ajax({
                          url: "loan_type_info.php",
                          type: "post",
                          async:true,
                          data:  {values:values , flag:flag},
                          dataType: 'html',
                          contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
                          success: function(data) {                           
                              $('#result').append('Response Data:');
                              $('#result').append(data);                          
                          },                  
                          error: function(jqXHR, textStatus, errorThrown) {
                             console.log(textStatus, errorThrown);
                          }
                      });
                  });         
  &lt;/script&gt;
  </code></pre>
  
  <p>I think php is not getting all the variables.I also follow this link <a href="https://stackoverflow.com/questions/6085649/ajax-multiple-data">AJAX - multiple data</a> and try with <code>data: {values,flag}</code> and <code>data: {values:values , flag:flag}</code> or <code>values={values:values , flag:flag}</code>. But still same offset problem. </p>
  
  <p>here is my php code:</p>
  
  <pre><code>&lt;?php
  // they all came from serialize data: values
  $loanid      = (isset($_POST['loanid'])) ? $_POST['loanid'] : "not";
  $loan_name   = (isset($_POST['loan_name'])) ? $_POST['loan_name'] : "not";
  $description = (isset($_POST['description'])) ? $_POST['description'] : "not";
  $amount      = (isset($_POST['amount'])) ? $_POST['amount'] : "not";
  $datestring  = (isset($_POST['textdatetimepicker1'])) ? $_POST['textdatetimepicker1'] : "not";
  $rate        = (isset($_POST['rate'])) ? $_POST['rate'] : "not";
  $date_arr = explode('/', $datestring);
  $date     = date("Y/m/d", strtotime($date_arr[2] . $date_arr[1] . $date_arr[0]));
  
  //  comes from  data: flag
  $flag  = (isset($_POST['flag'])) ? $_POST['flag'] : 0;
  ?&gt;
  </code></pre>
  
  <p>Please help me and let me know for any further information.Thanks.</p>