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);
    }
});
相关推荐
vistaup12 小时前
OKHTTP 默认构建包含 android 4.4 的TLS 1.2 以及设备时间不对兼容
android·okhttp
韩曙亮2 天前
【jQuery】jQuery 选择器 ④ ( jQuery 筛选方法 | 方法分类场景 - 向下找后代、向上找祖先、同级找兄弟、范围限定查找 )
前端·javascript·jquery·jquery筛选方法
摇滚侠2 天前
【程序员入门系列】jQuery 零基础入门到精通!Jquery 选择器 API
前端·javascript·jquery
Emma_Maria4 天前
本地项目html和jquery,访问地址报跨域解决
前端·html·jquery
2301_780669865 天前
Vue(入门配置、常用指令)、Ajax、Axios
前端·vue.js·ajax·javaweb
清山博客5 天前
jQuery easyui 扩展datetimebox控件,增加上午、中午、下午快速选择
前端·jquery·easyui
2601_949809596 天前
flutter_for_openharmony家庭相册app实战+相册详情实现
javascript·flutter·ajax
bug-0077 天前
关于前后端自动携带cookie跨域问题
okhttp
Southern Wind8 天前
从零封装一套企业级表格组件库 - 基于 Layui 的实战教程
前端·javascript·layui·jquery
满栀5858 天前
企业后台登录页面开发
开发语言·前端·javascript·jquery