简体   繁体   English

发送地图 <String,List<String> &gt;通过ajax作为请求参数

[英]Sending Map<String,List<String>> as request parameter through ajax

i want to send a Map through ajax request but i am getting 400 bad request. 我想通过ajax请求发送地图,但我收到400错误请求。 My data is like. 我的数据就像。

var idss1 = [];
var idss2 = [];
var idss3 = [];
var idss4 = [];
var idss5 = [];


    map[id_1] = idss1;
    map[id_2] = idss2;
    map[id_3] = idss3;
    map[id_4] = idss4;
    map[id_5] = idss5;

wehre all the keys (id_*) are string 我们所有的键(id_ *)是字符串

Ajax call is Ajax呼叫是

$.ajax({
        type:"POST",
        url: myurl,
        dataType: "text",
        data : {allIds : map},
        success: function(response) {...}

at server side my method signature is 在服务器端,我的方法签名是

public void myMethod(HttpServletRequest request, @RequestParam("allIds") Map<String, List<String>> ids) {
...
}

Kindly help me, i shall be thankful. 请帮助我,我将感激不尽。

1) You should never have variables names in a program whose only difference is a number. 1)程序中绝对不能有变量名称,变量名称的唯一区别是数字。 That is what arrays are for. 那就是数组的目的。 The names of the elements in the array are myArr[0], myArr[1], etc. 数组中元素的名称为myArr [0],myArr [1]等。

2) In java, you can do what's called 'serializing' an object. 2)在Java中,您可以执行“序列化”对象的操作。 Serializing converts an object to a string, and a string can be sent in an ajax request, and then the string can be unserialized in your servlet to create an object from the string. 序列化将对象转换为字符串,然后可以在ajax请求中发送字符串,然后可以在servlet中对字符串进行反序列化以从该字符串创建对象。

Serialization to String: How to binary (de)serialize object into/form string? 序列化为字符串: 如何将对象二进制化(反)序列化成字符串/形成字符串?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 发送多个参数 Ajax 字符串化请求时,所需的字符串参数“querycontent”不存在 - Required String parameter 'querycontent' is not present while sending multiple parameters Ajax stringify request with Jquery in Spring MVC Application 地图<String, String>作为 Spring Boot 应用程序中的请求参数 - Map<String, String> as request parameter in spring boot application 使用字符串和列表作为参数迭代哈希映射 - Iterate through a Hash Map with string and list as parameters request.getHeader(字符串值)参数列表 - List of parameter of request.getHeader(String value) 从 ajax 向 spring controller 发送数据:所需的字符串参数不存在 - sending data from ajax to spring controller: Required String parameter is not present 名单 <Map<String,String> &gt;遍历WebElement变量 - List<Map<String,String>> to iterate through WebElement variables 如何发送地图 <String, List<String> &gt;通过意图 - How to send Map<String, List<String>> through a intent 遍历列表<map<string, object> > map 在 Thymeleaf </map<string,> - Iterating through a List<Map<String, Object>> map in Thymeleaf 使用Apache CXF通过REST解析String []请求参数 - Parsing String[] Request Parameter through REST with Apache CXF 通过ajax在servlet中发送多个参数 - sending multiple parameter in servlet through ajax
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM