问题
I have a problem when dealing with the callback of a form submit, the code in client side is:
[...]
buttons: [{
text: 'submit',
formBind: true,
handler: function(){
formPanel.getForm().submit({
url: this.actionUrl,
waitMsg: TR['formdialog.messages.saving'],
success: function(form, action) {
this.close();
},
failure: function(form, action) {
if(action.failureType == Ext.form.Action.CLIENT_INVALID) {
Ext.Msg.alert('Failure', 'Client invalid');
}else if(action.failureType == Ext.form.Action.CONNECT_FAILURE){
Ext.Msg.alert('Failure', 'Connect failure');
}else if(action.failureType == Ext.form.Action.SERVER_INVALID){
Ext.Msg.alert('Failure', 'Server invalid');
}else{
Ext.Msg.alert('Failure', action.result.msg);
}
}
[...]
In the server side, the code is as simple as:
response = {'success':True, 'msg': 'Everything went better than expected'}
print response
return HttpResponse(content=json.dumps(response))
When trying with Firefox 3.6.17 the form remains with the wait message and does nothing. With Firebug 1.7.2 it can be seen in the net tab, the petition to the server and in console (running the server with runserver) I can see the print of the response. However, the action.response is empty and in Firebug I see an "Aborted" status. If I set breakpoints in success and failure it seems that the execution is not going through neither of them :S (is there any other possible case?).
When trying with Chrome 7.0.517.44 the execution seems to go through success (which is correct) but action.response is also empty and console reflects "Failed to load resource" (although in server console the response is correctly printed).
Update: With HttpFox I can see a NS_ERROR_NET_RESET (as well as with wireshark I can see that a packet with RST flag is sent by the server), but I have no clue of the reason of this behaviour :S.
回答1:
Try to set mimetype="application/json" in your view function
来源:https://stackoverflow.com/questions/8053690/extjsdjango-form-submit-success-failure-issue