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;
});