POST request to servlet not returning response | Community
Skip to main content
__96
October 16, 2015
Solved

POST request to servlet not returning response

  • October 16, 2015
  • 3 replies
  • 1793 views

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?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by aem_visi

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

3 replies

aem_visiAccepted solution
October 16, 2015

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

Lokesh_Shivalingaiah
October 16, 2015

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

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

__96
__96Author
October 16, 2015

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.