I have an object like this:
Object id: "myid" token: "sometoken"
I need to build a HTTP query-string and get something like this:
http://domain.com/file.html?id=myid&token=sometoken
Any ideas how I can do this?
I need to get the value of location from the URL into a variable and then use it in jQuery code: var thequerystring = "getthequerystringhere" $('html,body'). animate({scrollTop: $("div#" + thequerystring).
split('='); var key = params[0]; var value = params[1]; var obj = { [key] : value }; paramObj. push(obj); } console. log(paramObj); //Loop through paramObj to get all the params in query string.
The param() method creates a serialized representation of an array or an object. The serialized values can be used in the URL query string when making an AJAX request.
var obj = { id : 'myid', token : 'sometoken' }; alert($.param(obj));
You can use $.param()
to create your query-string parameters. This will alert id=myid&token=sometoken
.
This function is used internally to convert form element values into a serialized string representation.
Here is a demo: http://jsfiddle.net/RdGDD/
And docs: http://api.jquery.com/jquery.param
var obj = { id: 'myid', token: 'sometoken' }; var url = 'http://domain.com/file.html?' + $.param(obj);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With