<form
id="ff">
<input
type="text"
name="test1"/>
<input
type="text"
name="test2"/>
<input
type="text"
name="test3"/>
<input
type="text"
name="test4"/>
<input
type="button"
id="save"
value="save"/>
</form>
$("#save").on("click",
function
() { var
params = $("#ff").serializeArray();
var
j = {}; for
(var
item in
params) { j[params[item].name]
= params[item].value; }
$.ajax({
url:'index.html',
data:JSON.stringify(j),
type:'post',
dataType:'json',
headers:{
Accept:"application/json",
"Content-Type":"application/json" },
processData:false,
cache:false }).done(function
(data) { });
});
本文介绍了一种使用jQuery库和AJAX技术将HTML表单数据序列化并发送到服务器的方法。通过实例展示了如何获取表单元素的值,并将其转换为JSON格式的数据进行POST请求。

1758

被折叠的 条评论
为什么被折叠?



