View Full Version : REST response via Ajax request is empty

11 Jan 2013, 6:26 AM
I am sending an Ajax request to REST service. The response is JSON and should contain some data, but the expected data is missing and I am not sure how to debug the issue. Basically, the request is sending username and the service is simply sending the same back into the response. The problem seems to reside in EXTJS because I have a Java based REST client that makes the same request and the response is correct. The Chrome debugger shows the correct HTTP request and the empty JSON response. Some details below. Any suggestions how to debug this issue? Thank you!

Ajax request

url: 'atlas/login',
method: 'POST',
headers: { 'Accept': 'application/json' },
success: this.loginSuccess,
failure: this.loginfailure,
params: { username: 'pippo' }

Receiving EXTJS code

loginSuccess: function(record, operation) {
if (record.responseText) {
var loginResource = Ext.JSON.decode(record.responseText);
if (loginResource.links && loginResource.links.length > 0) {
var link = loginResource.links[0];
if (link.action == 'redirect') {
window.location = link.href;


Expected response (works from Java client)


Response in EXTJS


11 Jan 2013, 11:17 AM
What format does your rest service expect the params you send to be in? Having no idea what your REST service is expecting, I suspect that the "null" for username is being returned from your REST service because the data posted in the request is not in the format that your service expects it to be in.

Does your JAVA client show you a breakdown of the request that it sends? If so, I'd start by comparing what it generates (since you know that's working) and what ExtJS generates (via Firebug or Chrome dev tools), see if they match, and tweak either your service or your AJAX post to match what is expected.

14 Jan 2013, 7:36 AM
Thank you existdissolve. It was exactly the format of the parameters. The REST service was expecting query parameters, while the AJAX request was sending them as form parameters. I have modified the REST service (based on Jersey) to work with form parameters.

14 Jan 2013, 7:37 AM
Awesome, glad it helped!