ExtJS的+ Django的表单提交成功/失败的问题表单、问题、ExtJS、Django

2023-09-11 01:27:22 作者:承诺就像写在沙滩上的字

我有一个问题,当一个形式的回调处理提交时,code在客户端是:

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);
             }
         }
         [...]

在服务器端,code是简单的:

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))

在使用Firefox 3.6.17尝试的形式仍保留在等待消息,什么都不做。与萤火虫1.7.2它可以在网络选项卡中可以看出,该请愿书,服务器和控制台(运行服务器的runserver)我可以看到的响应打印。然而,action.response是空的,在Firebug我看到一个中止状态。如果我设置的成功和失败的断点似乎执行不经历他们都没有:S(?还有没有其他可能的情况下)

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?).

在Chrome浏览器尝试7.0.517.44的执行似乎要经过成功(这是正确的),但action.response也是空的,控制台反映无法加载资源(虽然在服务器控制台响应打印正确)。

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).

更新:随着HttpFox我可以看到一个NS_ERROR_NET_RESET(以及与Wireshark的,我可以看到,RST标志的包由服务器发送),但我不知道的原因这种行为:S。

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.

推荐答案

尝试在您的视图功能设置MIMETYPE =应用/ JSON的

Try to set mimetype="application/json" in your view function