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);
    }
});
相关推荐
满栀58517 小时前
jQuery 递归渲染多级树形菜单
前端·javascript·jquery
HIT_Weston19 小时前
104、【Ubuntu】【Hugo】搭建私人博客:搜索功能(AJAX请求)
ubuntu·ajax·okhttp
雨声不在19 小时前
okhttp的自定义dns解析
okhttp·dns
啥都不懂的小小白20 小时前
Vue Ajax与状态管理完全指南:从数据请求到全局状态控制
vue.js·ajax·vuex·插槽系统
w***76552 天前
JS vs jQuery:核心差异解析
开发语言·javascript·jquery
满栀5852 天前
分页插件制作
开发语言·前端·javascript·jquery
凛_Lin~~3 天前
安卓网络框架——OkHttp源码解析(基于3.14.x)
android·网络·okhttp
满栀5853 天前
插件轮播图制作
开发语言·前端·javascript·jquery
岁岁种桃花儿4 天前
XMLHttpRequest 从入门到实战:GET/POST 请求完整案例
ajax·okhttp
梦6505 天前
JavaScript (ES5)+ES6+jQuery 核心对象方法大全
javascript·es6·jquery