EXTJS7 BUG分析解决 form启用xhr2提交丢失所有表单数据

2020-06-19 16:44:49 浏览数 (1)

表单提交启用xhr2时会丢失所有表单数据

代码语言:javascript复制
form.submit({
	xhr2: true
	...
});

源码

  • form/Panel.js
代码语言:javascript复制
...
beforeAjaxSubmit: function(form, options, successFn, failureFn) {
	...
	if (Ext.feature.has.XHR2 && request.xhr2) {
        delete request.form;
		// 此处将表单值存入request.data有误,后续请求并没有从request.data取值
		// 可通过override: 'Ext.form.Panel'覆盖此方法修订,改为:
		// formData = request.rawData = new FormData(form);
        formData = request.data = new FormData(form);

        if (request.params) {
            Ext.iterate(request.params, function(name, value) {
                if (Ext.isArray(value)) {
                    Ext.each(value, function(v) {
                        formData.append(name, v);
                    });
                }
                else {
                    formData.append(name, value);
                }
            });

            delete request.params;
        }
    }
	...
}
...
  • Ext.data.Connection
代码语言:javascript复制
...
// 发起请求
request: function(options) {
    ...
   	// 装填请求信息
    requestOptions = me.setOptions(options, options.scope || Ext.global);
    request = me.createRequest(options, requestOptions);
    return request.start(requestOptions.data);
    ...
},
...
setOptions: function(options, scope) {
	...
	// 并没有使用options.data
	data = options.rawData || options.binaryData || options.xmlData || jsonData || null;
	...
	return {
        url: url,
        method: method,
        data: data || params || null
    };
}
...

0 人点赞