Dynamically retrieve all GETs from the URL

1

I'm dynamically loading my views with ajax using:

view = getUrlParameter('view') ? getUrlParameter('view') : window.location.href+="?view=newusers";

$.ajax({
  method: "post",
  url: "views/empregador/" + view + ".php",
  data: {
    auth: 'ajaxrequest'
  }
}).done(function(data) {
  $('#viewa').html(data);
});

This works perfectly for cases where you access a page that does not need GET parameters. However, in some requests I need to have my url be "views/empregador/" + view + ".php?meuGet=123&meuOutroGetAleatorio=123&..." .

My getUrlParameter function retrieves URL-specific parameters, forcing a check if 1 by 1 exists, which would be totally impractical for the level of application complexity.

Is there a method of dynamically capturing all GETs passed by the URL with javascript?

    
asked by anonymous 04.02.2018 / 03:36

1 answer

3

You can use the location.search function to get the complete query:

 var query = location.search;

If you want to manipulate them, there is already a response in a topic answering this: How do I capture parameters passed by the URL using javascript? / a>

    
04.02.2018 / 03:59