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);
    }
});
相关推荐
不考研当牛马2 天前
jQuery 核心速查与实战笔记
jquery
来恩10033 天前
jQuery对Ajax的支持
前端·ajax·jquery
来恩10034 天前
jQuery事件处理方法
前端·javascript·jquery
流年如夢4 天前
类和对象(中)
开发语言·javascript·ajax·ecmascript
你觉得脆皮鸡好吃吗5 天前
XSS渗透 COOKIE
网络·http·okhttp·网络安全学习
努力成为AK大王5 天前
从前端到数据库:一个 Web 项目的完整通信链路解析
前端·数据库·ajax·jdbc
来恩10038 天前
jQuery选择器
前端·javascript·jquery
彭于晏Yan8 天前
OkHttp 与 RestTemplate 技术选型对比
java·spring boot·后端·okhttp
JohnnyDeng948 天前
OkHttp 拦截器链与缓存策略:深度解析网络层的核心机制
okhttp·缓存
胖胖胖胖胖虎9 天前
okhttp Stream Load 含认证请求重定向
starrocks·okhttp