首页
归档
笔记
树洞
搜索
友言

文章详情

Interesting People Record Interesting.

/ JavaScript / 文章详情

jQ 表单提交

Sonder
2020-06-04
1180字
3分钟
浏览 (2.7k)

表单提交

html:

复制代码
<form action="/addemailcontact" id="sendCancelForm" onsubmit="return false">
 <textarea class="form-control" rows="7" name="Content" required></textarea>
 <div class="modal-footer">
   <button type="submit" class="btn black-btn" id="sendFormInfoBtn">submit</button>
 </div>
</form>

js:

复制代码
$("#sendCancelForm").on("submit", function(ev) {
 var ii = layer.load();
 var serializeUrl = $("#sendCancelForm").serializeArray();
 var FormRes =  serializeUrl.reduce(function(prev, cur) {
   prev[cur.name] = cur.value;
   return prev
 }, {});


 console.log(FormRes);


 var JSON_data = JSON.stringify(FormRes);
 console.log(JSON_data,"JSON_data")
 $.ajax({
   headers:{
     "Accept": "application/json; charset=utf-8",
     "Content-Type":"application/json"
   },
   type: 'PUT',
   data: JSON_data,
   dataType: 'json',
   url: 'xxxxx',
   success: function (res) {
     layer.close(ii);

   },
   error: function (xhr) {
     console.log("xhr = ",xhr);
   }
 });
 // //阻止submit表单提交
 // ev.preventDefault();
 // //或者return false
 // return false;
});
下一篇 / 基于bootstrap的面板选中效果

🎯 相关文章

💡 推荐文章

🕵️‍♂️ 评论 (0)