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);
    }
});
相关推荐
教练、我想打篮球5 小时前
120 同样的 url, header, 参数, 使用 OkHttp 能够成功获取数据, 使用 RestTemplate 报错
http·okhttp·resttemplate·accept
chilavert3186 小时前
技术演进中的开发沉思-258 Ajax:自定义事件
前端·ajax·okhttp
chilavert3186 小时前
技术演进中的开发沉思-259 Ajax:浏览器历史管理
javascript·ajax·okhttp·状态模式
降临-max1 天前
JavaWeb企业级开发---Ajax、
java·ajax·maven
踢球的打工仔1 天前
jquery的基本使用(5)
前端·javascript·jquery
踢球的打工仔2 天前
jquery的基本使用(3)
前端·javascript·jquery
踢球的打工仔2 天前
jquery的基本使用(2)
前端·javascript·jquery
华阙之梦2 天前
【仅公网互通的 Spark 集群通信与配置实战方案】
大数据·ajax·spark
C182981825752 天前
HttpURLConnection 是 Apache HttpClient 和 OKHttp 底层吗
okhttp·apache
C182981825753 天前
restTemplate/Feign(Spring Cloud)或OKHttp Apache HttpClient 这几个关系与底层实现
spring cloud·okhttp·apache