Ajax Mysqli filtering combine two functions

时间:2018-11-16 21:39:40

标签: javascript php ajax mysqli

I just got some simple ajax working on my output of an inventory page (Ajax Database select value returning '0' instead of string). My question now is can I combine two functions together to work as multi condition filtering?

My functions are:

<script>
function showMake(str) {
    if (str == "") {
        document.getElementById("inventory").innerHTML = "";
        return;
    } else { 
        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
                document.getElementById("inventory").innerHTML = this.responseText;
            }
        };
        xmlhttp.open("GET","includes/inc.inventorymake.php?make="+str,true);
        xmlhttp.send();
    }
}
</script>
<script>
function showBody(str) {
    if (str == "") {
        document.getElementById("inventory").innerHTML = "";
        return;
    } else { 
        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
                document.getElementById("inventory").innerHTML = this.responseText;
            }
        };
        xmlhttp.open("GET","includes/inc.inventorybody.php?body="+str,true);
        xmlhttp.send();
    }
}
</script>

Which are pretty much the same but call to two different php files now that are again identical except the filtered column is body instead of make.

I'm sure the functions would have to be rewritten entirely and there would be other things that need to be rewritten such as the html for the dropdown menus but just in case I'm wrong and it's something simple, I figured I'd ask here first.

Thanks.

0 个答案:

没有答案