JavaScript 函数,用于使用该参数创建 URL


javascript function to create url using the parameter

这是我有一个js函数,我想在其中使用参数值进行xmlhttp.open调用

  <script>
  function showStudents(str) {
      if (str == "") {
          document.getElementById("stuList").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 (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
              document.getElementById("stuList").innerHTML = xmlhttp.responseText;
          }
          else if (xmlhttp.readyState == 4 && xmlhttp.status == 404) {
              document.getElementById("stuList").innerHTML = 'Invalid URL';
          }
    }
    xmlhttp.open("POST", "<?php echo site_url("/rhadmin/testing/"); ?> + str ",true);
    xmlhttp.send();
    }
}
</script>

如果 'str' 参数的值为 6 - 则应 http://localhost/rhadmin/testing/6 最终网址

我需要做什么才能得到这个?

感谢对此的任何帮助。谢谢。

xmlhttp.open("POST", "<?php echo site_url("/rhadmin/testing/"); ?>"+str,true);