So, I am trying to do a simple data display. I've got my HTML with my p-tag where the processed data is supposed to be displayed, I've got my JS script with my 2 functions, one for updating the HTML and one for the AJAX request.
The php-script which is called currently does nothing more than returning the same data it got with
<?php $q = $_GET['q']; echo $q; ?>.
Heres the HTML:
<form  name="form1">
  <select onchange="showUser(this.value)" name="users" form="form1">
    <option value="">Select a person:</option>
    <option value="1">Peter Griffin</option>
    <option value="2">Lois Griffin</option>
    <option value="3">Joe Swanson</option>
    <option value="4">Glenn Quagmire</option>
  </select>
</form>
<br>
  <p id="txt"></p>
<script type="text/javascript" src="js/main.js"></script>
And here's the JS:
      var myData = "";
      function getData(parameter) {
        if (window.XMLHttpRequest) {
          var xhttp = new XMLHttpRequest();
        } else {
          xhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xhttp.onreadystatechange = function() {
          if (this.readyState == 4 && this.status == 200) {
            var myStatusTxt = this.statusText;
            myData = this.responseText;
          }
        };
        xhttp.open("GET", "http://192.168.0.154/testing/getuser.php?q=" + parameter , true);
        xhttp.send();
        return myData;
      }
    function showUser(str) {
      document.getElementById("txt").innerHTML = getData(str);
      console.log(str);
    };
 
    
"-Tag.
– Velioc Jan 22 '18 at 14:56