fields and url value

0

I have this url:

http://localhost/pagina.php?grado=2&escuela=urbano

I want to be able to take the degree and school fields with their values and place them in a variable called data, how can I do that, and try several ways but it marks me error

    
asked by JV93 07.11.2018 в 16:59
source

1 answer

1

You can get the current url with window.location.href , then support yourself in the URL class to extract the parameters:

var url = new URL('http://localhost/pagina.php?grado=2&escuela=urbano');
var grado = url.searchParams.get('grado');
console.log(grado);
    
answered by 07.11.2018 в 17:07