jQuery实现ajax语法,post请求发送数组对象(jquery)

$.ajax()代码模板

jQuery实现ajax语法为:$.ajax({}),其中{}为对象,对象里面的key键是固定的,比如:
1、type: 表示请求方式,一般为post或get
2、url表示请求的地址
3、contentType表示发送信息至服务器时内容编码类型
4、data表示发送到服务器的数据
5、dataType表示预期服务器返回数据的类型如:text,json,xml等等类型
6、success表示请求成功后的回调函数
7、error自动判断 (xml 或 html)。请求失败时调用此函数,等等

对象中包含数组对象

js 复制代码
let htLockRelationCard = {
    userList: userList,
    roomId: roomId,
    cardNumber: cardNum
};
$.ajax({
    url: `smartLockRoomRelationCard/cardDelivery`,
    type: "POST",
    contentType: "application/json",
    data: JSON.stringify(htLockRelationCard),
    dataType: "json",
    success: function (res) {
        console.log(res);
    }
});

数组对象

js 复制代码
$.ajax({
    url: `smartLockRoomRelationCard/cardDelivery`,
    type: "POST",
    contentType: "application/json",
    data: JSON.stringify(userList),
    dataType: "json",
    success: function (res) {
        console.log(res);
    }
});
相关推荐
CYY9510 小时前
OkHttp 和 Retrofit 封装使用
okhttp·retrofit
CYY951 天前
OkHttp 的使用
okhttp
学以智用12 天前
jQuery DataTables 完整实用教程
jquery
朝星12 天前
Android开发[14]:网络优化之OkHttp
android·okhttp·kotlin
学以智用14 天前
jQuery `serialize()` 详解
jquery
এ慕ོ冬℘゜14 天前
jQuery 高可用多图上传组件(企业级封装 + 踩坑全解 + 可直接上线)
前端·javascript·jquery
之歆14 天前
Promise 基础技术深度解析:从回调地狱到链式调用
前端·okhttp·promise
wuxia211814 天前
在5种环境中编写点击元素改变内容和颜色的JavaScript程序
javascript·微信小程序·vue·jquery·react
之歆14 天前
Ajax 基础技术深度解析:XHR 从入门到跨域
前端·ajax·okhttp