【发布时间】:2020-09-29 08:53:09
【问题描述】:
我想使用 javaScript ajax 发布带有正文的请求
如何在复选框、日期和名称上应用 Onchange 函数并将此数据发送到发布请求
对于复选框,如果选中则其值为 true,如果未选中则为 false
<form onsubmit="sectionWork()">
<div class="form-check">
<input type="checkbox" class="form-check-input" id="exampleCheck1">
<label class="form-check-label" for="exampleCheck1">Check me out</label>
</div>
<div class="form-group">
<label for="exampleInputDate">Date</label>
<input type="date" id="exampleInputDate" name="date">
</div>
<div class="form-group">
<label for="exampleName">Name</label>
<input type="text" aria-placeholder="Enter Name" name = "naming" class="form-control" id="naming" >
</div>
<button type="submit" class="btn btn-primary">Releasing</button>
</form>
这里是javascript
const sectionWork= () => {
let body = {
Checkbox: null,
Date: null,
name: null
}
$.ajax(url,
{
type : 'post',
data : body,
success: function (response) { // success callback function
console.log(response)
},
error: function (error) { // error callback
console.log(error)
$('#p').append('Error: ' + error);
}
});
}
【问题讨论】:
标签: javascript ajax