Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passing json array ajax

Trying to pass a array using ajax call.

info = [];
info[0] = 'hi';
info[1] = 'hello';

$.ajax({
    type: "POST",
    data: {info: info, "action": "getPatientRecords"},
    url: "/mobiledoc/jsp/ccmr/webPortal/carePlanning/servicePatientmilestoneModal.jsp",
    success: function(msg) {
        $('.answer').html(msg);
    }
});

However when i try to catch it on the server side using : request.getParameter("info"); //Displays null**

Also, if i wish to send an array of arrays ? is it possible?

I tried using serialize however my IE throws error that serialize : object doesnt support this property i Did include jquery lib.

like image 786
user1908568 Avatar asked Jun 09 '26 14:06

user1908568


2 Answers

You can use JSON.stringify(info) to create a JSON representation of the object/array (including an array of arrays). On the server side you should be able to get the string via getParameter and then unserialize it from JSON to create constructs JSP can use.

like image 94
Explosion Pills Avatar answered Jun 11 '26 04:06

Explosion Pills


Yes,It is Possible to send arrays.

var info_to_send = ['hi','hello'];

$.ajax({
    type: "POST",
    data: {info: info_to_send, "action": "getPatientRecords"},
    url: "/mobiledoc/jsp/ccmr/webPortal/carePlanning/servicePatientmilestoneModal.jsp",
    success: function(msg) {
        $('.answer').html(msg);
    }
});
like image 28
HIRA THAKUR Avatar answered Jun 11 '26 04:06

HIRA THAKUR