Forms ExtJS 7.2.0-表单提交在Chrome中不起作用
我正在尝试使用以下代码上载文件:Forms ExtJS 7.2.0-表单提交在Chrome中不起作用,forms,extjs,submit,extjs7,Forms,Extjs,Submit,Extjs7,我正在尝试使用以下代码上载文件: window = Ext.create('Ext.window.Window', { renderTo: Ext.getBody(), bodyPadding: '20 10', title: 'Upload file', autoDestroy: true, hidden: true, modal: true, layout: {
window = Ext.create('Ext.window.Window', {
renderTo: Ext.getBody(),
bodyPadding: '20 10',
title: 'Upload file',
autoDestroy: true,
hidden: true,
modal: true,
layout: {
type: 'hbox',
align: 'middle',
pack: 'center'
},
items: [
uploadForm = new Ext.form.Panel({
items: [
file = new Ext.form.field.File({
xtype: 'filefield',
name: 'fileName',
fieldLabel: 'File',
allowBlank: false,
buttonText: 'Select file...',
})
]
})
],
buttons: [{
text: 'Cancel',
handler: function () {
upload.hide();
}
},
{
text: 'Upload',
handler: function () {
var form = uploadForm.getForm();
if (form.isValid()) {
form.submit({
url: 'upload',
waitMsg: 'Uploading your file...',
scope: this,
success: function (form, action) {
upload.close();
var json = JSON.parse(action.response.responseText);
if (json.success) {
Ext.Msg.alert('Success', json.message);
} else {
Ext.Msg.alert('Error', json.message);
}
},
failure: function (form, action) {
upload.close();
try {
var json = JSON.parse(action.response.responseText);
Ext.create('Ext.window.MessageBox').show({
title: 'Failure',
msg: json.message
});
} catch (err) {
Ext.create('Ext.window.MessageBox')
.alert('Failure', 'Failed to parse response');
}
}
});
}
}
}]
});
代码在firefox和opera中运行,我成功地得到了响应,但在chrome on inspect network activity中,状态为Cancel,在控制台中我得到警告:资源被解释为文档,但使用MIME类型的application/json传输。因此,即使上传了文件,提交也总是返回失败。有人可以建议如何解决此问题吗?我已尝试将内容类型设置为text/html,但没有收到警告,但提交请求状态仍然被取消。我还以为您的内容类型是“application/json”,不是吗?是的,我还在form.submit上设置了content type in headers属性,但在文档中注意到,在文件上载期间不会发送头。我尝试使用Ext.Ajax.Request而不是form.submit,但无法实现。你还有别的想法吗?