doudao1950 2018-02-23 05:43
浏览 63
已采纳

显示复选框所选项目的结果

I am calling Api : $url = 'https://plapi.ecomexpress.in/track_me/api/mawbd/?awb=awbnumber&order=' . $orderrecords[$k]["order_id"] . '&username=admin&password=admin123'; and fetching Status results of all Order IDS & displaying in php page when we refresh php page.

But I dont want to Call APi everytime when we refresh page. But When i select Order IDs through checkbox, than when i click on button "Show Status" , than only i want to Call Api & update the Selected Order IDs status in web page.

Url Output

enter image description here

enter image description here

PHP

<?php

           $tabindex=1;
          function checkecomstatus($orderid)
          {
            $data['username']='admin';
            $data['password']='ouhk78epe34csmed46d';
            $data['awb']=$orderid;

            $url = 'https://plapi.ecomexpress.in/track_me/api/mawbd/?awb=awbnumber&order='.$orderid.'&username=admin&password=ouhk78epe34csmed46d';
            $ch = curl_init();                    
            curl_setopt($ch, CURLOPT_URL,$url);
            curl_setopt($ch, CURLOPT_POST, true);  
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);         

            $output = curl_exec ($ch); 
            curl_close($ch);
            $res = explode("
",$output);

            if ( ! isset($res[13])) 
            {
               $res[13] = null;
            }
            $status = str_replace('</field>.','',$res[13]);
            $statusfinal = str_replace('<field type="CharField" name="status">','',$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->executeUpdate($sqlecom);      
            }

            return $statusfinal;
          }

?>                  
         <p><button type= "button" >Show Status</button></p>
          <table class="tbl-qa" border="1">
           <thead>
            <tr>            
              <th class="table-header">ID</th>
              <th class="table-header">ORDERID</th>            
              <th class="table-header">Status</th>         
            </tr>
          </thead>
          <tbody id="table-body">
          <?php

          if(!empty($orderrecords)) 
          {
            foreach($orderrecords as $k=>$v) 
            {?>
              <tr class="table-row" id="table-row-<?php echo $orderrecords[$k]["id"]; ?>" tabindex="<?php echo $tabindex;?>">
                <td><input type="checkbox" onclick="assignorderids('<?php echo $orderrecords[$k]["order_id"]; ?>')" name="assigneeid" id="assigneeid-<?php echo $orderrecords[$k]["order_id"]; ?>" value="<?php echo $orderrecords[$k]["order_id"]; ?>"></td>

                <td><?php echo $orderrecords[$k]["order_id"]; ?></td>

               <td><?php echo checkecomstatus($orderrecords[$k]["order_id"]);?></td>           

            </tr>
            <?php 
            $tabindex++;
            }
          }?>
          </tbody>
        </table> 
        <input type="hidden" name="ordercheckallIDs" id="ordercheckallIDs" value="<?php echo $ordercheckall;?>"/> 

Javascript

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 < 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;
            }
        }
    }
  • 写回答

1条回答 默认 最新

  • douwen9343 2018-02-23 05:53
    关注

    This seems like you don't know about jQuery basics. If you can grab data from API but is firing on refresh then put it in trigger fire approach. something like if you have fetchData() function which fetches data from API as per the checkbox then don't fire it directly instead do something like $('#fetch-button-id').click(function() { fetchData(); });

    and if you have just put fetch data from api code directly into document then add those code into function then call it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序