Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
90
rated 0 times [  93] [ 3]  / answers: 1 / hits: 84547  / 12 Years ago, wed, march 28, 2012, 12:00:00

I got a JavaScript object which I would like to get x-www-form-urlencoded.



Something like $('#myform').serialize() but for objects.



The following object:



{
firstName: Jonas,
lastName: Gauffin
}


would get encoded to:



firstName=Jonas&lastName=Gauffin (do note that special characters should get encoded properly)


More From » jquery

 Answers
71

I'm surprised that no one has mentioned URLSearchParams



var prms = new URLSearchParams({
firstName: Jonas,
lastName: Gauffin
});
console.log(prms.toString());
// firstName=Jonas&lastName=Gauffin

[#86559] Tuesday, March 27, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jaidyn

Total Points: 633
Total Questions: 102
Total Answers: 100

Location: Trinidad and Tobago
Member since Thu, Dec 1, 2022
2 Years ago
;