SEND A GET REQUEST WITH JS SCRIPT code example

Example 1: create http request javascript

const Http = new XMLHttpRequest();
const url='https://jsonplaceholder.typicode.com/posts';
Http.open("GET", url);
Http.send();

Http.onreadystatechange = (e) => {
  console.log(Http.responseText)
}

Example 2: send info with get request in js

document.getElementById("form").onsubmit=function(e){
                e.preventDefault();
                var str=document.getElementById("val1").value;
                var xhr=new XMLHttpRequest();
                xhr.open("GET","new.php?val1="+str,true);
                xhr.onload=function(){
                    console.log(this.responseText);
                }
                xhr.send();
         }
//php file
<?php
if(isset($_GET['val1'])){
   
   $a=$_GET['val1'];
   echo $a;
}