tags:

views:

174

answers:

2
+1  Q: 

jQuery and $_GET

Let's say I have this url: www.example.com/test.php?page=4

How do i retrieve the value of $_GET['page'] with jQuery? o_O

+7  A: 

Check out the jQuery Query String Object Plugin

Justin Niessner
I worked! Thanks :)
cvack
+1  A: 

If you don't have jQuery or you don't want to use a plugin, you can use this code from netlobo.com:

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

then use it as follows:

var pageNumber = gup( 'page' );
fudgey