0
var Dados = {};
Dados.email = jQuery("#email").val();
Dados.nome= jQuery("#nome").val();
var urlparams = Dados.serialize();
My console returns Dados.serialize is not a Function there is some error in the code?
0
var Dados = {};
Dados.email = jQuery("#email").val();
Dados.nome= jQuery("#nome").val();
var urlparams = Dados.serialize();
My console returns Dados.serialize is not a Function there is some error in the code?
5
You are using the wrong method. The method .serialize()
, according to the documentation, it is used to create a string in the pattern URL-encoded through a jQuery object that has selected form fields, such as input
s, select
s and textarea
s, or the form itself.
What you seek is the function $.param()
, which creates a serialized representation of the data of an object:
const string = $.param({
name: 'Luiz Felipe',
nickname: 'lffg'
});
console.log(string);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
+1 Good answer! I would just add that the serialize
should be used, or in a form
, or in a selection of input
, textarea
and select
, as shown in the documentation you mentioned: $( "input, textarea, select" ).serialize();
Thank you! I will edit the reply soon. However, turn me more on to the function $.param()
, since she is the focus of the question, and not .serialize()
. :)
I understand, I only found valid in this case because it is cited the documentation of serialize
and would be more complete for those who read. Even if the function $.param
be the focus. D
I edited it. Thanks! ;)
Browser other questions tagged jquery
You are not signed in. Login or sign up in order to post.
That’s because
Dados
is not a jQuery object. And if you dojQuery(Dados).serialize()
?– Woss
@Andersoncarloswoss sorry I didn’t understand your question
– Josimara
The parameters come blank
– Josimara
var Data = {}; Data.email = "email"; Data.name = "name"; var urlparams = jQuery(Data). serialize(); Alert(urlparams);
– Josimara