0

Am trying to use ajax to send two form values into the GET array for processing by a PHP file in the server. I only know of passing a single argument, every time i try to pass two, the result i get in the PHP file is a concatenated string from the two parameters. The PHP query needs each parameter at different locations for processing. Here is the ajax call with explanations on what i need.

    dep=document.getElementById("departure").value;
    dest=document.getElementById("destination").value;
    alert(dep+" "+dest);
   //the line below is what needs two parameters, i try this php file is good no errors
   //the only parameter i passed is q which works with the server file
    xmlhttp.open("GET","schedule.php?q="+dep,true);
    xmlhttp.send();
    </script>

When I do this, it returns a concatenated version of the two parameters

 dep=document.getElementById("departure").value;
    dest=document.getElementById("destination").value;
    alert(dep+" "+dest);
   //the line below is my trial version of passing two parameters into the GET channel
    xmlhttp.open("GET","schedule.php?q="+dep+"?m="+dest,true);
    xmlhttp.send();

Please help me pass the two parameters into the GET array and access them separately in the server file.

Rene Pot
  • 24,003
  • 7
  • 67
  • 90
  • You're very close, but your query string is still malformed. Looking at https://stackoverflow.com/a/8064705/296555, your query string should look like `"dep=value_for_departure&dest=value_for_destination"`. Then, you need to concatenate that to your URL separated by a single `?`. So your final URL would look like `"schedule.php?dep=value_for_departure&dest=value_for_destination`. – waterloomatt Sep 14 '21 at 12:51

0 Answers0