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

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

form.submit({
	xhr2: true
	...
});

源码

  • form/Panel.js
...
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
...
// 发起请求
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
    };
}
...

posted on 2020-05-07 15:24  路过君  阅读(49)  评论(0编辑  收藏  举报

导航