Skip to Content
0
Former Member
Feb 11, 2015 at 06:14 PM

$.request.parameters.get to get an Array in XSJS

2042 Views

Hi,

I am making an Ajax GET request and sending a json object. I am able to capture the string values in xsjs whereas for the array, it says undefined. How can I get the Array values? Here is how the code looks like:

Ajax Call:

in the data: results is an array.

$.ajax({

url : getServiceUrl("createUserTags.xsjs"),

type : "GET",

data : {"objectId" : objectId , "userId" : oUserId , "tagsArray" : results},

async : false,

dataType : "json",

success : function(data){

console.log(data);

}

});

in my xsjs file:

var objectId = $.request.parameters.get("objectId");

var tagsArray = $.request.parameters.get("tagsArray"); //---------> I think this is where the issue is

var userId = $.request.parameters.get("userId");

var conn = $.db.getConnection();

try{

for (var c = 0; c< tagsArray.length; c++){

// do something....

}

conn.commit();

$.response.setBody('{"success": "true" }');

$.response.headers.set("Access-Control-Allow-Origin", "*");

$.response.contentType = "application/json";

}catch(e){

$.response.setBody('{"Fail": "' + tagsArray + '"}');

$.response.headers.set("Access-Control-Allow-Origin", "*");

$.response.contentType = "application/json";

}

I get the error message as {"Fail" : "undefined"}, how can I get the tagsArray values?

Thank you

Prab