0

I have a page with the following format : http://www.test.com/get.php?pSuccess=success I need to retrieve the pSuccess value using jQuery. I tried with the following code but I can't get it working..

$(document).ready(function(){
function GetURLParameter(sParam)
{
    var sPageURL = window.location.search.substring(1);
    var sURLVariables = sPageURL.split('&');
    for (var i = 0; i < sURLVariables.length; i++) 
    {
        var sParameterName = sURLVariables[i].split('=');
        if (sParameterName[0] == sParam) 
        {
            return sParameterName[1];
        }
    }
}​
var success = GetURLParameter('pSuccess');

}); 
Apul Gupta
  • 3,044
  • 3
  • 22
  • 30
  • 2
    Possible duplicate: http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript – Nick Mar 18 '15 at 14:00

1 Answers1

0

I use this native function:

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

In this case pget('pSuccess') gives the correct value.

Mario Araque
  • 4,562
  • 3
  • 15
  • 25