title: Call php function onclick button in same page
body: <p>Once I select check boxes &amp; <code>OnClick</code> <strong>Insert</strong> Button I am calling php function present in <code>api.php</code> page to  display results under <strong>status</strong> column.
  But its not fetching any results .</p>
  
  <p><a href="https://i.stack.imgur.com/OlP0V.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OlP0V.png" alt="enter image description here"></a></p>
  
  <p>below is api url page results :</p>
  
  <p><a href="https://i.stack.imgur.com/LaB4s.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LaB4s.png" alt="enter image description here"></a></p>
  
  <p><strong>table.php</strong> - php code</p>
  
  <pre><code>         &lt;p&gt;&lt;button type= "button" id="show_status" &gt;Show Status&lt;/button&gt;&lt;/p&gt;
            &lt;table class="tbl-qa" border="1"&gt;
             &lt;thead&gt;
              &lt;tr&gt;            
                &lt;th class="table-header"&gt;ID&lt;/th&gt;
                &lt;th class="table-header"&gt;ORDERID&lt;/th&gt;            
                &lt;th class="table-header"&gt;Status&lt;/th&gt;         
              &lt;/tr&gt;
            &lt;/thead&gt;
            &lt;tbody id="table-body"&gt;
            &lt;?php
  
            if(!empty($orderrecords)) 
            {
              foreach($orderrecords as $k=&gt;$v) 
              {?&gt;
                &lt;tr class="table-row" id="table-row-&lt;?php echo $orderrecords[$k]["id"]; ?&gt;" tabindex="&lt;?php echo $tabindex;?&gt;"&gt;
                  &lt;td&gt; 
  &lt;input type="checkbox" name="assigneeid" class="assigneeid-order" value="&lt;?php echo $orderrecords[$k]["order_id"]; ?&gt;"&gt; 
  &lt;/td&gt;
  
                  &lt;td&gt;&lt;?php echo $orderrecords[$k]["order_id"]; ?&gt;&lt;/td&gt;
  
                 &lt;td id="&lt;?php echo checkecomstatus($orderrecords[$k]["order_id"]);?&gt;"&gt;&lt;/td&gt;         
  
              &lt;/tr&gt;
              &lt;?php 
              $tabindex++;
              }
            }?&gt;
            &lt;/tbody&gt;
          &lt;/table&gt; 
          &lt;input type="hidden" name="ordercheckallIDs" id="ordercheckallIDs" value="&lt;?php echo $ordercheckall;?&gt;"/&gt;
  </code></pre>
  
  <p><strong>table.php</strong> - javascript code </p>
  
  <pre><code> $('#show_status').click(function(){ 
  var selected = []; 
  $('.assigneeid-order input:checked').each(function() { 
  selected.push($(this).val()); 
  }); 
  
  var jsonString = JSON.stringify(selected); 
  $.ajax({ 
  type: "POST", 
  url: "api.php", 
  data: {data : jsonString}, 
  success: function(response){ 
  $.each(response, function(index, val) { 
  
  $("#"+index+"").html(val); 
  }); 
  } 
  }); 
  
  });
  
  
      function assignallorderids()
        {
         var checkstatus=$("#checkall").is(":checked");
  
          if(checkstatus==true)
          {
            var id=document.getElementById("ordercheckallIDs").value;  
            document.getElementById("orderids").value=id;
            $("input:checkbox[name='checkassigneeid']").prop('checked',true); 
          } 
          else
          {
            $("input:checkbox[name='checkassigneeid']").prop('checked',false);  
            document.getElementById("orderids").value='';
          }    
        }
  
  
  
          function assignorderids(oid)
              {
                 var checkstatus=$("#assigneeid-"+oid).is(":checked");       
                  var morderId =document.getElementById("orderids").value;
                  if(checkstatus==false)
                  {
                      var arrayorder = JSON.parse("[" + morderId + "]");
                      document.getElementById("orderids").value='';
                      for (var i = 0; i &lt; arrayorder.length; i++) {           
                          var orderstatusValue=arrayorder[i];
                          if(orderstatusValue!=oid){
                              if (document.getElementById("orderids").value=='')
                              {
                                  document.getElementById("orderids").value=orderstatusValue; 
                              }
                              else
                              {
                                  var newvalue=document.getElementById("orderids").value;
                                  document.getElementById("orderids").value=newvalue+","+orderstatusValue;                        
                              }
                          }                       
                      }
                  }
                  else
                  {
                      if(morderId=='')
                      {
                          document.getElementById("orderids").value=oid;
                      }
                      else
                      {
                          document.getElementById("orderids").value=morderId+","+oid;
                      }
                  }
              }
  </code></pre>
  
  <p><strong>api.php</strong></p>
  
  <pre><code> &lt;?php
  
  $curl_data['username']='outthinking781346'; 
  $curl_data['password']='ouhk78epe34csmed46d'; 
  
  
  $data = json_decode(stripslashes($_POST['data'])); 
  
  
  foreach($data as $id){ 
  
  $orderid = $id; 
  $curl_data['awb']=$orderid; 
  $response = array(); 
  
  $url = 'plapi.ecomexpress.in/track_me/…'.$orderid.'&amp;username=outthinking781346&amp;password=ouhk78epe34csmed46d'; 
  $ch = curl_init(); 
  $ch = curl_init(); 
  curl_setopt($ch, CURLOPT_URL,$url); 
  curl_setopt($ch, CURLOPT_POST, true); 
  curl_setopt($ch, CURLOPT_POSTFIELDS, $curl_data); 
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
  
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
  
  $output = curl_exec ($ch); 
  curl_close($ch); 
  $res = explode("\n",$output); 
  
  if ( ! isset($res[13])) 
  { 
  $res[13] = null; 
  } 
  $status = str_replace('&lt;/field&gt;.','',$res[13]); 
  $statusfinal = str_replace('&lt;field type="CharField" name="status"&gt;','',$status); 
  if($statusfinal!='') 
  { 
  $sqlecom = "UPDATE do_order set in_transit='".$statusfinal.".',tconformed_by='Ecom' where order_id=".$orderid; 
  $db_handleecom = new DBController(); 
  $resultecom = $db_handleecom-&gt;executeUpdate($sqlecom); 
  } 
  
  // store the responce in array 
  
  $response[$orderid] = $statusfinal; 
  
  return $response; 
  }
  
  ?&gt;
  </code></pre>