Expand my Community achievements bar.

SOLVED

POST request to servlet not returning response

Avatar

Level 4

I have a code snippet where I am hittting a Servlet with POST request, the servlet is returning the correct response but in my code I am getting that response object as NULL. The code snippet is below :

CQ.shared.HTTP.post('/bin/services/damwhitelistcheck', function(options, success, tzOffset, response) { if(success) { var jsonResponse = CQ.shared.HTTP.eval(response); } }, {filePath: fileUploadLocation,extension: extension}, this, true, true);

This behaviour is also observed in many places wherever I am trying to implement things like this. I am not sure why response object comes as NULL because when I see in firebug response is coming correct. Can anyone help me on this?

1 Accepted Solution

Avatar

Correct answer by
Level 3

In the past i have used succesfully a jquery AJAX request to post data to the Sling Servlet, as shown in the following link.

http://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html

View solution in original post

3 Replies

Avatar

Correct answer by
Level 3

In the past i have used succesfully a jquery AJAX request to post data to the Sling Servlet, as shown in the following link.

http://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html

Avatar

Level 10

I think response should be captured at http.post level like

var resp  = CQ.shared.HTTP.post('/bin/services/damwhitelistcheck',

Avatar

Level 4

Ultimately solved that using a different way making an ajax call 

var url = CQ.HTTP.noCaching("/bin/services/myservlet"); url = CQ.HTTP.addParameter(url, "filePath", fileUploadLocation); url = CQ.HTTP.addParameter(url, "extension", extension); var response = CQ.HTTP.get(url); var allowed = false; if (CQ.HTTP.isOk(response)) { var data = CQ.Util.eval(response); allowed = data.Allowed; if(allowed == "false"){ alert("allowed is false"); } }

Here I am passing the arguments to the url using the addParameter method. And everything is working fine using this way.