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);
    }
});
相关推荐
没差c7 天前
RetrofitClient写接口、导包、配置、路径
java·spring boot·okhttp
wcy03109 天前
POST为什么会发送两次请求
javascript·ajax
刺客码10 天前
Layui 表格固定列行高错位问题解决方案
前端框架·layui·jquery·web
事圆则缓18 天前
OkHttp + Retrofit 协作原理
okhttp·retrofit
降临-max20 天前
接口自动化(TestNG+OKHttp)
软件测试·okhttp·自动化·testng
小刘在重生~20 天前
Django|Ajax 入门、JSON 返回、ECharts 图表、文件上传完整笔记
ajax·django·json
吴声子夜歌21 天前
Java扩展——OkHttp
java·开发语言·okhttp
এ慕ོ冬℘゜21 天前
前端实战:基于jQuery递归实现通用树形组织菜单(可直接复用)
前端·javascript·jquery
零域码客21 天前
一文掌握 jQuery + Flask 全栈核心知识点(前端交互 + 后端接口 + 前后端联调)
前端·python·ajax·flask·jquery·前后端联调·web全栈
暖焰核心21 天前
C++模板进阶——特化全解
javascript·c++·jquery