0

I need to pass a variable called Henry that carries the value '1234' through XMLhttprequest. However, the value on the variable cannot be passed instead the variable name 'Henry' has passed through CGI. So, may I ask how could I pass the value instead of the variable name ???

Code :

<!DOCTYPE html>
<html>
<body>

<h1>The XMLHttpRequest Object</h1>

<button type="button" onclick="loadDoc()">Request data</button>

<p id="demo"></p>

<script>
 function loadDoc() {
     var xhttp = new XMLHttpRequest();
     xhttp.onreadystatechange = function() {
      if (this.readyState == 4 && this.status == 200) {
          document.getElementById("demo").innerHTML = this.responseText;
          }
        };

    var Henry = "1234";

    xhttp.open("GET", "demo_get2.asp?fname=Henry&lname=Ford", true);

    xhttp.send();
}
</script>

</body>
</html>

Results :

The XMLHttpRequest Object

Request data

Hello Henry Ford

==> The result got Hello Henry Ford instead of Hello 1234 Ford 
  • can u try this ? xhttp.open("GET", "demo_get2.asp?fname="+Henry+"&lname=Ford", true); – Khalil Oct 28 '20 at 04:18
  • or `const params = new URLSearchParams({fname: Henry, lname: "Ford"}); xhttp.open("GET", \`demo_get2.asp?${params}\`, true)` – Phil Oct 28 '20 at 04:24

0 Answers0