javascript - 复杂的ajax请求到spring post方法

标签 javascript ajax spring-boot

我需要将复杂的数据结构传递给 post 方法。我不知道如何在js方法中形成它。我需要传入post方法Map<String, List<String>> 。如何在js中得到这个结构。以及如何在post方法中传递它?

最佳答案

@ADyson建议,您需要的 JSON 数据形式看起来是这样的:

{ "a": ["1", "2", "3"], "b": ["4", "5", "6"] }

您可以使用fetch发送ajax请求。如果您不想使用 fetch,那么还有很多替代方案,但不值得在此列出。

fetch('http://www.yourendpoint.com/whatever-route', {
  method: 'POST',
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({a: ["1", "2", "3"], b: ["4", "5", "6"] }),
})

关于javascript - 复杂的ajax请求到spring post方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55628140/

相关文章:

javascript - 为什么我无法使用 Modernizr 检测 IE9 中的媒体查询

javascript - 可以使用 $.getJSON 检索数据但不能使用 $.ajax

java - 使用 Spring Boot 编写 Spring Batch

javascript - 为什么这个ajax请求有一个数据字符串,里面有一堆带破折号的数字?

spring-boot - 为什么我们需要将日志消息发送到elasticsearch?

java - 无法保存用户: Cannot deserialize instance of `java.util.ArrayList<>` out of START_OBJECT token at [Source: (BufferedInputStream)

javascript - 为什么设置 scrollTop 无法设置正确的位置?

javascript - React App - Chrome 磁盘缓存 JS 文件

javascript - Vue.js - "Bind" Bootstrap 模态到 Vue 模型

jquery - 如何在 jquery 和 laravel 中通过 request 传递数据表中的两个参数