jQuery 中有一套专门针对 A JAX 的封装,功能十分完善,经常使用,需要着重注意。
两个jQuery-Ajax的使用手册:
https://www.jquery123.com/jQuery.ajax/
https://www.w3school.com.cn/jquery/jquery_ref_ajax.asp
1. $.ajax
$.ajax({
url: './get.php',
type: 'get',
dataType: 'json',
data: { id: 1 },
beforeSend: function (xhr) {
console.log('before send')
},
success: function (data) {
console.log(data)
},
error: function (err) {
console.log(err)
},
complete: function () {
console.log('request completed')
}
})
常用选项参数介绍:
url:请求地址
type:请求方法,默认为 get