Ajax 表单提交方式

原文地址:

返回主页

https://wangdoc.com/javascript/bom/form.html

参考: 朱小杰 https://www.cnblogs.com/zhuxiaojie/p/4783939.html

参考:https://www.cnblogs.com/Renyi-Fan/p/9581951.html

表单提交方式

<form onsubmit="return false" action="#" method="post"> <input hidden="hidden" value="{{ csrf_token }}"> <p>用户名:<input type="text"/></p> <p>密 码:<input type="password"/></p> <p><input type="button" value="登录">&nbsp;<input type="reset" value="重置"></p> </form> //方式一: $("#submit").click(function () { $.post("url", $("#form_id").serialize(), function (result) { if (result.success) { alert(result.msg); } } ); }); //方式二: var formData = new FormData($("#form_id")[0]); formData.append("file", $("#input_file_id").prop(\'files\')[0]); $.ajax({ url: "", type: "post", data: form, processData: false, contentType: false, success: function (data) { if (data.success) { alert(data.msg); } else { alert(data.msg); } }, }); //方式三: let rows = $(\'#table1\').bootstrapTable("getSelections"); var formData = $("#add_program"); rows.forEach(function (item) { formData.append("<input name=\'id\' value=\'" + item.id + "\'>") }); $.post("/LEDScreen/programManage/addIMG/", formData.serialize(), function (data) { if (data.success) { alert(data.msg); } }, ); //方式四 : $("#submit").click(function () { $.post("url", { "username":$("username").val(), "password":$("password").val(), }, function (result) { if (result.success) { alert(result.msg); } } ); });

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zwpyxs.html