【发布时间】:2016-09-19 19:33:27
【问题描述】:
基本上我有一系列用于过滤数据表的按钮。
我的前两个按钮可以正常工作:
<button onclick="filter('open');" class="open">Open</button>
<button onclick="filter('closed');"class="closed">Closed</button>
函数如下所示:
function filter(st, location) {
if(st == "") {
document.getElementById("exams").innerHTML = "";
return;
} else {
if(window.XMLHttpRequest) {
var xmlhttp = new XMLHttpRequest();
} else {
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("exams").innerHTML = xmlhttp.responseText;
}
};
xmlhttp.open("GET", "ajax.php?st="+st+"&location="+location, true);
}}
在 ajax.php 文件中,我正在检查 st 参数以设置我在查询中使用的变量:
if (isset($_GET["st"])) {
$status = $_GET["st"];
} else {
$status = null;
}
$query = "SELECT examID, `status`, site, first_name, last_name, exam_name, institution FROM exams WHERE status = '{$status}'";
现在我想根据另一个按钮单击传递另一个参数以进一步过滤数据。我不确定要为参数添加什么才能使其正常工作。
<button onclick="filter();" class="new-york">New York</button>
【问题讨论】:
-
你想在哪里传递另一个参数?
-
如果我有另一个按钮,如 我想将位置 New York 传递给第二个 filter() 函数参数“location”
-
如果您的函数被声明为使用 2 个参数,请不要只传递一个...创建第二个接收位置作为参数的函数。
标签: javascript php mysql ajax filtering