Jump to content

[SOLVED] $_GET[''] in javascript


plutomed

Recommended Posts

I see...

I found this somewhere in the vast cavern of knowledge we call the web:

 

<script>
function getQueryVariable(variable) {
   var query = window.location.search.substring(1);
   var vars = query.split("&");
   for (var i=0;i<vars.length;i++) {
      var pair = vars[i].split("=");
      if (pair[0] == variable) {
         return pair[1];
      }
   }
   alert('Query Variable ' + variable + ' not found');
}
</script>

 

Now make a request to page.html?x=Hello

 

<script>
alert( getQueryVariable("x") );
</script>

 

Note that it only works with GET, not POST.

 

Hope that helps.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.