PDA

View Full Version : ExtJs4.1 - Form data not being submitted to server



bomslang
2 Sep 2012, 1:56 AM
Folks,

I am using ExtJS 4.1. I am trying to submit a form using Ext.Ajax.request() and REST on server side.

Here's my Ajax request,


var params = form.getValues();
Ext.Ajax.request({
url: 'feedback/newFeedback.action',
params: params,
success: function(response) {
Ext.Msg.alert('Success');
},
failure: function(response) {
Ext.Msg.alert('Failure', 'Error : '+response.responseText);
},
callback: function(options, success, response) {
Ext.Msg.alert('Title', response.responseText);
}
});


Server Side code :-


@RequestMapping(value="/feedback/newFeedback.action")
public @ResponseBody Map<String,? extends Object> create(@RequestBody Object data) throws Exception {
try{
List<Feedback> feedbacks = feedbackService.create(data);
return getMap(feedbacks); // this will return json once control reaches here ..
} catch (Exception e) {
return getModelMapError("Error trying to create contact.");
}
}


When I click on Submit button, I get the below error



message: /feedback/newFeedback.action
description The requested resource (/feedback/newFeedback.action) is not available.


What am I missing ?

bomslang
2 Sep 2012, 3:32 AM
Now, if I try out with form.submit(), it throws me a different exception


var form = Ext.getCmp('fdForm').getForm();
if(form.isValid()) {
form.submit({
waitMsgTitle: 'Title',
url: 'feedback/newFeedback.action',
method: 'POST',
success: function(response) {
Ext.Msg.alert('Success');
},
failure: function(response) {
Ext.Msg.alert('Failure');
}
});
}


Exception :-


POST http://localhost:8080/faq/feedback/newFeedback.action 415 (Unsupported Media Type) ext-all-debug.js:37622
Ext.define.request ext-all-debug.js:37622
Ext.define.doSubmit ext-all-debug.js:30042
Ext.define.run ext-all-debug.js:30016
(anonymous function)


What is happening ? What is wrong with my code ?

Any sample example of form submission using REST ?

vietits
2 Sep 2012, 6:30 PM
It seems that your webserver does not support request to 'http://localhost:8080/faq/feedback/newFeedback.action'. What will happen if you will access to this url by using your browser?

bomslang
3 Sep 2012, 4:42 AM
Thanks for your reply.

I tried running it under both - Eclipse Internal web browser as well as Chrome.
Both shows up the same error.