dtdh11647 2013-04-10 15:33
浏览 40
已采纳

将$ _GET变量传递给javascript函数[重复]

This question already has an answer here:

i have a php page that displays a table from multiple MySQL queries and from their use a JavaScript function to sort the column results, all that works fine, my problem is i need to refresh the results of those queries every 10 seconds or so which works fine(with a meta-refresh), the problem is the refresh after column sorting. when the page refreshes the sorting is reset also. here is a snippet of the sorting function;

    <script>
    function tablesort(which){  <-----I tried using the $_GET method you suggested
                                <-----But i get a "missing formal parameter" error
                                <-----When also using this suggestion and use the
                                <-----"onclick" i get a "tablesort" is not defined
                                <-----error
$(document).ready(function(){
if(which == '1.0'){<!--This sorts the pause row, descending --> 
$("#Mtable").tablesorter({sortList: [[1,0]]});
}
if(which == '2.1'){<!--This sorts the total dialer row, descending --> 
$("#Mtable").tablesorter({sortList: [[2,1]]});
}
if(which == '3.0'){<!--This sorts Wrap-up time row, descending --> 
$("#Mtable").tablesorter({sortList: [[3,0]]});
}
if(which == '4.1'){<!--This sorts donation amount row, descending --> 
$("#Mtable").tablesorter({sortList: [[4,1]]});
}
if(which == '5.1'){<!--This sorts Up-sale row, descending --> 
$("#Mtable").tablesorter({sortList: [[5,1]]});
}
if(which == '6.1'){<!--This sorts the Monthl donation row, descending --> 
$("#Mtable").tablesorter({sortList: [[6,1]]});
}
if(which == '7.1'){<!--This sorts the verified sales row, descending --> 
$("#Mtable").tablesorter({sortList: [[7,1]]});
}
if(which == '8.1'){<!--This sorts the calles per hour row, descending --> 
$("#Mtable").tablesorter({sortList: [[8,1]]});
}
if(which == '9.1'){<!--This sorts the payments per hour row, descending --> 
$("#Mtable").tablesorter({sortList: [[9,1]]});
}
if(which == '10.1'){<!--This sorts the average sale row, descending --> 
$("#Mtable").tablesorter({sortList: [[10,1]]});
}
if(which == '11.1'){<!--This sorts the sales total row, descending --> 
$("#Mtable").tablesorter({sortList: [[11,1]]});
}
    });
    }
    </script>

here are the links that sort the table'

        Sort by: 
<a onclick="tablesort('1.0')"> Lowest Pause<a/>&nbsp &nbsp
<a onclick="tablesort('2.1')"> Highest Dialer<a/>&nbsp &nbsp
<a onclick="tablesort('3.0')"> Best Wrap-up<a/>&nbsp &nbsp

because of the refresh im wanting to pass the variable data from the onlcick to the URL similar to $_GET so it would would something like and then read into the sorting function;

localhost/dbtabke.php?which=2.1 <----exact URL example being used

any help on how to do that would be greatly appreciated, thanks in advance.

@prabeen giri i have provided the complete function, thanks again

</div>
  • 写回答

2条回答 默认 最新

  • dongranding3909 2013-04-12 14:10
    关注

    I ended doing the following using $_GET,here is the code;

        <body>
        <!--This gets the element from the URL to set the Sorting, so the page
            can be refreshed without losing the sorting-->
        <body onload="sorttable.innerSortFunction.apply(document.getElementById('<?php echo $_GET["id"]; ?>'), [])">
    
        <!--table headers that are used to determine columns to sort by-->
        echo "<th id=\"dialertime\">".ucfirst("Dial Time")."</th>
    ";
        echo "<th id=\"pausetime\">".ucfirst("Pause Time")."</th>
    ";
    
        ...*other table info*
        <!--links that sort the specific row-->
        <a href="?id=wrap-by-time"> Wrap-up time<a/>&nbsp &nbsp
        <a href="?id=wrap-by-percent"> Wrap-up %<a/>&nbsp &nbsp
        </body>
    

    thanks for everyone's input, hope it helps

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析
  • ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao
  • ¥20 Vite 打包的 Vue3 组件库,图标无法显示
  • ¥15 php 同步电商平台多个店铺增量订单和订单状态
  • ¥15 关于logstash转发日志时发生的部分内容丢失问题
  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题