JS

WAYS TO BUILD QUERY STRINGS IN JAVASCRIPT

URL SEARCH PARAMS OBJECT var query = new URLSearchParams({    name : "John Doe",   email : "john@doe.com",   colors : JSON.stringify(["R", "G", "B"]) }); 

TO APPEND MORE DATA query.append("KEY", "VALUE");

CONVERT TO STRING var url = "http://site.com/page?" + query.toString();

URL SEARCH PARAMETERS

01

URI OBJECT & PARAMETERS var uri = new URI("http://site.com/page"); uri.setSearch({   name : "John Doe",   email : "john@doe.com",   colors : JSON.stringify(["R", "G", "B"]) });

TO APPEND MORE DATA uri.addSearch("KEY", "VALUE");   CONVERT TO STRING var url = uri.toString();

URIJS LIBRARY

02

TARGET URL var url = encodeURI("http://site.com/pg");

APPEND PARAMETERS url += "?name=" + encodeURIComponent("John Doe"); url += "&email=" + encodeURIComponent("john@doe.com"); url += "&KEY=" + encodeURIComponent("VALUE");

MANUAL URL STRING

03