PDA

View Full Version : Form Submit always success



yugikhoi
2 Sep 2010, 6:06 AM
Hi, I face a very rare problems that my form submit always success even I set respond
response.getWriter().write("{success:false}");

Below is my code for submit handle and jsp page



submitHandler: function () {
Ext.Ajax.request({
url: 'test.jsp',
method:'POST',
params: this.getValues(),
success: function(f,a){
Ext.Msg.alert('Success', "Your Case has been successfully added");
},
failure: function(f,a){
if (a.failureType === Ext.form.Action.CONNECT_FAILURE){
Ext.Msg.alert('Failure', 'Server reported:'+a.response.status+' '+a.response.statusText);

}
if (a.failureType === Ext.form.Action.SERVER_INVALID){
Ext.Msg.alert('Warning', a.result.errormsg);

}
}
});
}
jspPage


<%
response.getWriter().write("{success:false}");
response.getWriter().close();


%>


Anyone have any ideas? Thanks.

Condor
2 Sep 2010, 6:09 AM
success:false is a logical failure (a form submit would interpret this as failure), but a connection (=Ext.Ajax) doesn't process the content, so as long as it receives a status=200 the response is valid.

yugikhoi
2 Sep 2010, 6:16 AM
Thanks, I understand that. However, how can I set that submit is false, for example if i want to do manual return error on form submit at server side and return back that message to user.

Condor
2 Sep 2010, 6:22 AM
You will have to evaluate the response in the the success handler to see if it is really success:true.

ps. Why are you not using the build-in form.submit?

yugikhoi
2 Sep 2010, 6:23 AM
Can you show me reference for that or coding for that. I still do not know how to do that.

Thanks a lot.

I just have a quick view and see this code, is it the particular way to do as your suggestion:



var jsonData = Ext.util.JSON.decode(oResponse.getResponseHeader.JSON_STATUS);
if (jsonData.success === false) {
//show error
}

Condor
2 Sep 2010, 6:28 AM
What is oResponse.getResponseHeader.JSON_STATUS? You should be using:

success: function(response){
var jsonData = Ext.decode(response.responseText);
...
}

yugikhoi
2 Sep 2010, 6:35 AM
Thanks so much, it is done as your code show. You help me a lot.