2

i want to send a Map through ajax request but i am getting 400 bad request. 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

Ajax call is

$.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.

7
  • 1
    Can you construct a JSON list and send ? Should it be dataType: "text"? Commented May 14, 2013 at 7:06
  • i want to send it as a map not a list. How can i use a json list instead of map, can you kindly help? Commented May 14, 2013 at 7:10
  • 1
    So you can send a JSON map, there are lots of tutorials to do so in net !!! Commented May 14, 2013 at 7:11
  • what exception are u getting? Commented May 14, 2013 at 7:13
  • @Kshitij 400 bad request Commented May 14, 2013 at 7:15

1 Answer 1

0

1) You should never have variables names in a program whose only difference is a number. That is what arrays are for. The names of the elements in the array are myArr[0], myArr[1], etc.

2) In java, you can do what's called 'serializing' an object. 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.

Serialization to String: How to binary (de)serialize object into/form string?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.