标签:表单提交 oca success jquer mit ons pre post orm
<form id="form1" method="post" enctype="multipart/form-data"> <fieldset> <legend>用Ajax把Form表单提交到远程服务器Api</legend> <div class="form-group"> <label class="col-sm-6 control-label" for="ds_host">选择文件</label> <div class="col-sm-4"> <input type="file" name="file" id="inpFile" dirname="inpFile" /> </div> <div class="col-sm-2"> <input type="button" value="提交" id="inpUpload" /> </div> </div> </fieldset> <script src="/plugins/jquery-3.3.1.min.js"></script> <script src="/plugins/easyui/jquery.easyui.min.js"></script> <script> $(document).ready(function () { $("#inpUpload").click(function () { var fileObj = $("#inpFile").get(0).files[0]; if (fileObj == null) { alert("请选择要上传的文件"); return false; } $("#form1").form("submit", { url: "http://localhost:19501/Files/ReceiveFileTest", onSubmit: function (params) { //提交前检查 return true; }, success: function (data) { console.log(data); var data = eval(‘(‘ + data + ‘)‘); alert(JSON.stringify(data)); } }); }); }); </script> </form>
标签:表单提交 oca success jquer mit ons pre post orm
原文地址:https://www.cnblogs.com/hofmann/p/12627892.html