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);
    }
});
相关推荐
降临-max2 天前
接口自动化(TestNG+OKHttp)
软件测试·okhttp·自动化·testng
小刘在重生~2 天前
Django|Ajax 入门、JSON 返回、ECharts 图表、文件上传完整笔记
ajax·django·json
吴声子夜歌3 天前
Java扩展——OkHttp
java·开发语言·okhttp
এ慕ོ冬℘゜3 天前
前端实战:基于jQuery递归实现通用树形组织菜单(可直接复用)
前端·javascript·jquery
零域码客3 天前
一文掌握 jQuery + Flask 全栈核心知识点(前端交互 + 后端接口 + 前后端联调)
前端·python·ajax·flask·jquery·前后端联调·web全栈
暖焰核心3 天前
C++模板进阶——特化全解
javascript·c++·jquery
额鹅恶饿呃3 天前
Asynchronous JavaScript And XML(异步的JS和XML )
okhttp
泡海椒4 天前
JQuick-Curl 性能分析:并发场景下的性能表现与调优,第三方接口调用不只要快写也要稳跑
java·开发语言·okhttp
泡海椒4 天前
JQuick-Curl 二次开发:自定义解析器、扩展点开发指南,如何把框架能力真正变成团队资产
java·开发语言·okhttp·maven
摇滚侠5 天前
《SpringBoot 3:入门与应用实战》第 9 章 跨域问题 阅读笔记 27
spring boot·笔记·okhttp