PDA

View Full Version : Get Servlet response from form.submit()



ssamuel68
16 May 2013, 2:33 PM
Hi, Im having a problem getting the response from my servlet with the success.


mainForm.submit({
url: 'http://sam:8080/test.access.http/Test',
params: Ext.urlEncode(params),
method:'POST',
enctype:'multipart/form-data',
headers: {'Content-type':'multipart/form-data'},
success: function(form, action) {
console.log(action);
}
});


When I get the action.response.responseText is empty however if I use the debug console from chrome and go to "Network" I see my request and under the response tab I see the response from my servlet: {success: true, message:"Test"}

The Code on my servlet is this one:


response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("{success: true, message:'Test'}");
out.close();



What I need to change on my out for getting the desire response?

Thx

tobiu
17 May 2013, 4:26 AM
since you are using "message", try


console.log(action.result.message);


or just action.result and inspect the object.

Your response is no valid JSON, but the framework should be able to handle it this way. better would be:



{"success": true, "message":"Test"}

ssamuel68
17 May 2013, 6:12 AM
I change my output to this:
Java:

out.print("{\"success\": true, \"message\":\"Test\"}");

The respnose from my servlet
43852

console.log(action);
43853
Here you can see that the response text is empty, maybe Im getting an invalid json?

ssamuel68
21 May 2013, 12:04 PM
The problem is that my servlet is on glassfish and my app is on apache so, when I call my servlet it says is cross domain.

Thats why is not working.

I need a workaround here

ssamuel68
31 May 2013, 11:59 AM
Well, my solution was configuring my proxy on the apache server:

First I enable the proxy setting on my apache: a2enmod proxy_http

Then I redirect all my petitions on the config so is not a cross domain petition.