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);
    }
});
相关推荐
csdn_aspnet8 小时前
JavaScript AJAX 库
javascript·ajax
初见_Dream9 小时前
Retrofit+OkHttp+ViewModel
xml·okhttp·retrofit
林的快手1 天前
伪类选择器
android·前端·css·chrome·ajax·html·json
还是鼠鼠1 天前
详细介绍:封装简易的 Axios 函数获取省份列表
前端·javascript·vscode·ajax·前端框架
清风细雨_林木木2 天前
wangEditor 编辑器 Vue 2.0 + Nodejs 配置
vue.js·okhttp·编辑器
不会&编程4 天前
第四章 Vue 中的 ajax
前端·vue.js·ajax
Leven1995275 天前
Spark 性能优化 (三):RBO 与 CBO
ajax·性能优化·spark
Dontla5 天前
jQuery介绍(快速、简洁JavaScript库,诞生于2006年,主要目标是简化HTML文档操作、事件处理、动画和Ajax交互)
javascript·html·jquery
WeiLai11126 天前
DeepSeekApi对接流式输出异步聊天功能:基于Spring Boot和OkHttp的SSE应用实现
人工智能·spring boot·后端·okhttp
闲暇部落6 天前
Android网络框架——OKHttp
android·java·okhttp