Home >Web Front-end >JS Tutorial >jquery serialization method example analysis_jquery

jquery serialization method example analysis_jquery

WBOY
WBOYOriginal
2016-05-16 15:55:531560browse

The examples in this article describe the jquery serialization method. Share it with everyone for your reference. The specific analysis is as follows:

When doing ajax, serialization is often needed,
serialize() can only serialize forms. (Note: Only name can be used for the content in the form)

There is now an object:

Copy code The code is as follows:
var obj={a:1,b:2,c:3};

How to serialize it?
Can it be done with $H(obj).toQueryString() using prototype? Is there any method in jqueyr?

The answer is yes, jquery provides $.param().

var obj={a:1,b:2,c:3};
var k = $.param(obj);
alert(k) // 输出 a=1&b=2&c=3

Okay, let’s try it. . ^_^.

Example of serialize serialization. .

1. jquery selector selects all inputs in the form (type is text and radio)
2. serialize() to serialize it

var msg = $("#innerbox input[type=text],#innerbox input[type=radio]").serialize();
$.ajax({
type: "POST",
url: "add.php",
data: msg,
success: function(data){ $(".showMsg").html(data); }
});

I hope this article will be helpful to everyone’s jQuery programming.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn