Error in serialize jquery

0
var Dados = {};

Dados.email = jQuery("#email").val();
Dados.nome= jQuery("#nome").val();

var urlparams = Dados.serialize();

My console returns Data.serialize is not a function have any errors in the code?

    
asked by anonymous 25.09.2018 / 22:22

1 answer

5

You are using the wrong method. The .serialize() method, according to the documentation, is used to create a string in the URL-encoded via a jQuery object that has selected form fields, such as input s, select and textarea s, or the form itself.

What you are looking for is the $.param() function, which creates a representation serialized from an object's data:

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>

Reference:

25.09.2018 / 22:42