Fetch GET parameters in JS/jQuery

If you have a URL with some GET parameters as follows:


and need to get the values of each parameters then below is a nifty piece of code solving your requirement.

JavaScript has nothing built in for handling query string parameters.

You could access location.search, which would give you from the ? character on to the end of the URL or the start of the fragment identifier (#foo), whichever comes first.

You can then access QueryString.c

JSON, AJAX and jQuery

Today I was working on JSON.
1) Requirement was to get the data from a server in a JSON object. Store it into request object.
2) And on an HTML page, it was required to fire an AJAX request, get the data from the Servlet created in step 1.

3) When i fired a request to servlet directly in browser window, it used to print JSON object that it returns. But when i make a request thru AJAX call… the data is never displayed.


JSON object must follow the structure of the JSON object.
You cannot add any extra println in the resulting JSP. It must ONLY and ONLY print JSON object.

You can validate your JSON from www.jsonlint.com

See more : http://api.jquery.com/jQuery.ajax/