JQuery获取表单数据
<form id="form-box"> ... </form>
JSON字符串格式:
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){ } });
未经允许不得转载:w3h5 » JQuery获取form表单数据及数据提交
原创文章,作者:kirin,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/228444.html