First, the server-side:
C # version
#regionURL parameter action/// <summary> ///URL parameter Action/// </summary> Public classUrlpagehelper {/// <summary> ///add a URL parameter in regular-expression mode/// </summary> /// <param name= "key" ></param> /// <param name= "value" ></param> /// <returns></returns> Public Static stringAddurlparm (stringKeystringvalue) { stringURL =HttpContext.Current.Request.RawUrl; URL= Regex.Replace (Url +"&",@"(.*)(\?| &)"+ key +"=[^&]+? (&) (.*)","$1$2$4", regexoptions.ignorecase); URL= Url.remove (Url.length-1); if(Url.contains ('?') ) {Url=string. Format ("{0}&{1}={2}", URL, key, value); } Else{URL=string. Format ("{0}? {1}={2}", URL, key, value); } returnUrl; } } #endregion
PHP version
/** * Add URL parameter * @param string $url original URL * @param string $key key * @param string $value value * @retu RN string New URL*/ Private functionAdd_querystring_var ($key,$value) { $url=$this-URL; $url=Preg_replace('/(. *) (\?| &) '.$key.‘ =[^&]+? (&) (. *)/I ', ' $1$2$4 ',$url.‘ & '); $url=substr($url, 0,-1); if(Strpos($url,‘?‘) ===false){ return($url.‘?‘.$key.‘ = '.$value); } Else { return($url.‘ & '.$key.‘ = '.$value); } }
Then the client's
(function($) {$.extend ({Request:function(m) {varsvalue = Location.search.match (NewRegExp ("[\?\&]" + M + "= ([^\&]*) (\&?)", "I")); returnSvalue? Svalue[1]: svalue; }, Urlupdateparams:function(URL, name, value) {varR =URL; if(r! =NULL&& r! = ' undefined ' && r! = "") {Value=encodeURIComponent (value); varReg =NewRegExp ("(^|)" + name + "= ([^&]*) (|$)"); varTMP = name + "=" +value; if(Url.match (reg)! =NULL) {R=Url.replace (eval (reg), TMP); } Else { if(Url.match ("[\?]") ) {R= URL + "&" +tmp; } Else{R= URL + "?" +tmp; } } } returnR; } });}) (jQuery);
How to use the client:
$. Urlupdateparams (Window.location.href, "Order", "111")
Summary: Methods for adding URL parameters to the client and server side using regular