send info with get request in js

Solutions on MaxInterview for send info with get request in js by the best coders in the world

showing results for - "send info with get request in js"
Josué
01 May 2017
1document.getElementById("form").onsubmit=function(e){
2                e.preventDefault();
3                var str=document.getElementById("val1").value;
4                var xhr=new XMLHttpRequest();
5                xhr.open("GET","new.php?val1="+str,true);
6                xhr.onload=function(){
7                    console.log(this.responseText);
8                }
9                xhr.send();
10         }
11//php file
12<?php
13if(isset($_GET['val1'])){
14   
15   $a=$_GET['val1'];
16   echo $a;
17}