javascript web api

  • 61
  • 0

不是每個瀏覽器都可用

<input type="text" id="test">
<button type="submit" onclick="UserAction()">進入運動中心</button>
<input type="text" id="test1">
<script language="javascript">
    function UserAction() {

        var v = document.getElementById("test").value;
        //alert(v);
        var xhttp = new XMLHttpRequest();
        xhttp.open('GET', "http://localhost:60443/api/values/A" + v, false);
        xhttp.setRequestHeader("Content-type", "application/json");
        xhttp.send();
        var response =xhttp.responseText;
        //alert(response);
        document.getElementById("test1").value = response+v
    }
</script>