Query Archives : Binary Bits https://blog.binarybits.net/tag/query/ Bits & Pieces - A blog by Kannan Balasubramanian Mon, 03 May 2021 10:50:10 +0000 en-GB hourly 1 https://wordpress.org/?v=6.5.2 Get query string parameter using JavaScript https://blog.binarybits.net/get-query-string-parameter-using-javascript/ https://blog.binarybits.net/get-query-string-parameter-using-javascript/#respond Tue, 18 Jul 2017 06:40:39 +0000 https://blog.binarybits.net/?p=924 Following code will help in fetching the value of a query string parameter. function GetQueryStringParameter(parameter) { var search = location.search.substring(1); var queryStringParameters = JSON.parse('{"' + decodeURI(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"') + '"}') return queryStringParameters[parameter]; } Usage: If URL is http://server/page.html?id=1 Then usage would be GetQueryStringParameters(“id”) which would return 1

The post Get query string parameter using JavaScript appeared first on Binary Bits.

]]>
Following code will help in fetching the value of a query string parameter.

function GetQueryStringParameter(parameter) {
    var search = location.search.substring(1);
    var queryStringParameters = JSON.parse('{"' + decodeURI(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"') + '"}')
    return queryStringParameters[parameter];
}

Usage:

If URL is http://server/page.html?id=1

Then usage would be GetQueryStringParameters(“id”) which would return 1

The post Get query string parameter using JavaScript appeared first on Binary Bits.

]]>
https://blog.binarybits.net/get-query-string-parameter-using-javascript/feed/ 0
Decoding Query String with Unicode Characters https://blog.binarybits.net/decoding-query-string-with-unicode-characters/ https://blog.binarybits.net/decoding-query-string-with-unicode-characters/#respond Fri, 31 Jul 2015 09:35:42 +0000 https://blog.binarybits.net/?p=719 Recently I came across an issue where the query string had unicode characters and ASP.NET’s “HttpUtility.UrlDecode” was not properly converting the characters. After searching few minutes came across the following solution posted by cjsharp1 at Stackoverflow. private string GetQueryStringValueFromRawUrl(string queryStringKey) { var currentUri = new Uri(HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.RawUrl); var queryStringCollection = […]

The post Decoding Query String with Unicode Characters appeared first on Binary Bits.

]]>
Recently I came across an issue where the query string had unicode characters and ASP.NET’s “HttpUtility.UrlDecode” was not properly converting the characters. After searching few minutes came across the following solution posted by cjsharp1 at Stackoverflow.

private string GetQueryStringValueFromRawUrl(string queryStringKey)
{
    var currentUri = new Uri(HttpContext.Current.Request.Url.Scheme + "://" + 
        HttpContext.Current.Request.Url.Authority + 
        HttpContext.Current.Request.RawUrl);
    var queryStringCollection = HttpUtility.ParseQueryString((currentUri).Query);
    return queryStringCollection.Get(queryStringKey);
}

The post Decoding Query String with Unicode Characters appeared first on Binary Bits.

]]>
https://blog.binarybits.net/decoding-query-string-with-unicode-characters/feed/ 0