jQuery API jQuery API 中英文对照版 - jQuery在线查询手册
formSerialize(true)

formSerialize(true)

Serializes form data into a 'submittable' string. This method will return a string in the format: name1=value1&name2=value2 The semantic argument can be used to force form serialization in semantic order. If your form must be submitted with name/value pairs in semantic order then pass true for this arg, otherwise pass false (or nothing) to avoid the overhead for this logic (which can be significant for very large forms).

返回值

String

参数

  • true (semantic): if serialization must maintain strict semantic ordering of elements (slower)

示例

说明:

Collect all the data from a form into a single string

jQuery 代码:
var data = $("#myForm").formSerialize(); $.ajax('POST', "myscript.cgi", data);