Node.js: Difference between req.query[] and req.params

Given this route app.get(‘/hi/:param1’, function(req,res){} ); // regex version app.get(/^\/hi\/(.*)$/, function(req,res){} ); // unnamed wild card app.get(‘/hi/*’, function(req,res){} ); and given this URL http://www.google.com/hi/there?qs1=you&qs2=tube You will have: req.query { qs1: ‘you’, qs2: ‘tube’ } req.params { param1: ‘there’ } When you use a regular expression for the route definition, capture groups are provided in the … Read more

How to send JSON instead of a query string with $.ajax?

You need to use JSON.stringify to first serialize your object to JSON, and then specify the contentType so your server understands it’s JSON. This should do the trick: $.ajax({ url: url, type: “POST”, data: JSON.stringify(data), contentType: “application/json”, complete: callback }); Note that the JSON object is natively available in browsers that support JavaScript 1.7 / … Read more

Append values to query string

You could use the HttpUtility.ParseQueryString method and an UriBuilder which provides a nice way to work with query string parameters without worrying about things like parsing, URL encoding, …: string longurl = “http://somesite.example/news.php?article=1&lang=en”; var uriBuilder = new UriBuilder(longurl); var query = HttpUtility.ParseQueryString(uriBuilder.Query); query[“action”] = “login1”; query[“attempts”] = “11”; uriBuilder.Query = query.ToString(); longurl = uriBuilder.ToString(); // … Read more

Add querystring parameters to link_to

The API docs on link_to show some examples of adding querystrings to both named and oldstyle routes. Is this what you want? link_to can also produce links with anchors or query strings: link_to “Comment wall”, profile_path(@profile, :anchor => “wall”) #=> <a href=”http://stackoverflow.com/profiles/1#wall”>Comment wall</a> link_to “Ruby on Rails search”, :controller => “searches”, :query => “ruby on … Read more

Change URL parameters and specify defaults using JavaScript

I’ve extended Sujoy’s code to make up a function. /** * http://stackoverflow.com/a/10997390/11236 */ function updateURLParameter(url, param, paramVal){ var newAdditionalURL = “”; var tempArray = url.split(“?”); var baseURL = tempArray[0]; var additionalURL = tempArray[1]; var temp = “”; if (additionalURL) { tempArray = additionalURL.split(“&”); for (var i=0; i<tempArray.length; i++){ if(tempArray[i].split(‘=’)[0] != param){ newAdditionalURL += temp + … Read more

How to remove the querystring and get only the URL?

You can use strtok to get string before first occurence of ? $url = strtok($_SERVER[“REQUEST_URI”], ‘?’); strtok() represents the most concise technique to directly extract the substring before the ? in the querystring. explode() is less direct because it must produce a potentially two-element array by which the first element must be accessed. Some other … Read more