スキップしてメイン コンテンツに移動

Build Get Parameter String from Javascript Object or Map

This is just a quick tips... I think you can easily understand whole thing from the code below.
// example data used for get parameters. You can use plain javascript object if you want.
var map = ["name1":"value1", "name2":"value2"];

// Ok, let’s build string...
var parameters = [];
for(var prop in map)
{
  // if the name part (prop) contains the characters to uri encode, 
  // use encodeURIComponent as well for the name part.
  parameters.push(prop + "=" + encodeURIComponent(map[prop])); 
}
var parametersStr = parameters.join("&");

コメント