【发布时间】:2020-06-23 18:24:55
【问题描述】:
我有这样的形式
items: [{
xtype: 'form',
itemId: 'form',
bodyPadding: 5,
url: 'upload',
items: [{
xtype: 'fileuploadfield',
name: 'file',
fieldLabel: 'label',
emptyText: 'enter',
labelWidth: 60,
width: 590,
msgTarget: 'side',
allowBlank: false,
buttonText: 'browse'
}],
buttons: [
{
text: 'upload',
itemId: 'loadButton'
}]
}]
然后点击处理程序
onLoadBtn: function (button) {
var form = button.up('form').getForm(),
if (form.isValid()) {
form.submit({
scope: this,
submitEmptyText: false,
fileupload:true,
success: function (form, action) {
var response = Ext.JSON.decode(action.response.responseText, true);
if (response.success) {
Ext.Msg.show({
title: 'success',
msg: response.message,
buttons: Ext.Msg.OK,
icon: Ext.Msg.INFO
});
} else {
this.error(response.message);
}
},
failure: function (form, action) {
var response = Ext.JSON.decode(action.response.responseText, true);
this.error(response.message);
},
});
}
},
来自服务器端的端点返回带有 json 正文的响应
{"success" : "true", "message" : "Success"}
,但在浏览器网络响应正文为空。
请求有标头
Accept : 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
如果我把它改成
Accept : 'application/json'
然后重新发送请求,我得到了正确的 json 正文的响应。
任何想法,需要在表单或处理程序中更改什么,以便更改接受标头?
【问题讨论】:
-
“standardSubmit: true”有什么帮助吗?
-
谢谢!响应现在有 json 正文,但是请求的结果是用 json 打开新选项卡并且不调用成功或失败方法。
-
看起来 'accept' 标头是由浏览器设置的,无法更改。
标签: json file extjs upload submit