Wednesday, June 5, 2024
 Popular · Latest · Hot · Upcoming
99
rated 0 times [  106] [ 7]  / answers: 1 / hits: 58760  / 13 Years ago, thu, march 31, 2011, 12:00:00

I have a javascript object that I need to flatten into a string so that I can pass as querystring, how would I do that? i.e:



{ cost: 12345, insertBy: 'testUser' } would become cost=12345&insertBy=testUser



I can't use jQuery AJAX call for this call, I know we can use that and pass the object in as data but not in this case. Using jQuery to flatten to object would be okay though.



Thank you.


More From » jquery

 Answers
101

You want jQuery.param:



var str = $.param({ cost: 12345, insertBy: 'testUser' });
// cost=12345&insertBy=testUser


Note that this is the function used internally by jQuery to serialize objects passed as the data argument.


[#92981] Wednesday, March 30, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
guadalupec

Total Points: 610
Total Questions: 91
Total Answers: 91

Location: Guernsey
Member since Tue, Jul 6, 2021
3 Years ago
;