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);
    }
});
相关推荐
一壶浊酒..4 小时前
ajax局部更新
前端·ajax·okhttp
一壶浊酒..1 天前
什么是AJAX
前端·javascript·ajax
一枚前端小能手2 天前
🔧 jQuery那些经典方法,还值得学吗?优势与式微的真相一次讲透
前端·javascript·jquery
enki08153 天前
【CANN训练营】+开源之星+GitCode算子开发环境快速搭建手册
javascript·ecmascript·jquery
加洛斯4 天前
AJAX 知识篇(2):Axios的核心配置
前端·javascript·ajax
洛克大航海4 天前
Ajax基本使用
java·javascript·ajax·okhttp
星秀日4 天前
JavaWeb--Ajax
前端·javascript·ajax
小小星尘s4 天前
Python编程实战从基础到高级的完整指南
ajax
我是大头鸟7 天前
XMLHttpRequest 异步请求servlet 上传文件并且带有参数
ajax·servlet
梦65010 天前
JQ 的 AJAX 请求方法
前端·ajax