HTML
<form id="form-box">
...
</form>
JQuery 获取表单数据
JQuery 获取表单数据:
let json = $('#form-box').serialize();
console.log('json:', json); // 输入:json:name=w3h5&type=web
对象格局:
let data = {};
let value = $('#form-box').serializeArray();
$.each(value, function (index, item) {data[item.name] = item.value;
});
let json = JSON.stringify(data);
console.log(json);
/*
* 输入:{"name":"asd","type":"1"}
*/
JQuery form 表单提交
$("#form-box").submit();
ajax 异步提交
$.ajax({
type: "POST",
url: "/post.php",
data: json,
dataType : "json",
success: function(respMsg){}});