提交数据url太长导致提交失败

使用了dojo开发。在datagrid过滤的时候。为了让过滤好处理,直接设置为完全二叉树的方式来存查询条件。但是在提交数据的时候,默认是get?url的方式。结果导致条件选择一两个,url会特别长。然后会报404错误。差点把前面的设计推掉,重来。项目就差一小部分了。时间上也来不及了。硬着头皮,看了一天的js源代码,我只能说,俺对js的世界无法理解啊。反复的试验了好久,硬是将rest的get请求,改为了post请求。代码如下:

 require(["dojo/_base/declare", "dojox/rpc/JsonRest", "dojox/data/JsonRestStore", "dojo/dom", "dojo/domReady!"],
function (declare, rpcJsonRest,JsonRestStore, locale, dom) {
return declare("mydata.JsonRestStore", [dojox.data.JsonRestStore], {//我的rest并不标准{Data:data,ErrorNo:1,ErrorInfo:errorinfo}这种形式。
_processResults: function (results, deferred) {
// index the results
if (results.ErrorNo > ) {
alert(results.ErrorInfo);
throw new Error(results.ErrorInfo || '');
}
var count = results.Data.TotalRowCount;
results = results.Data.Items;
// if we don't know the length, and it is partial result, we will guess that it is twice as big, that will work for most widgets
return { totalCount: deferred.fullLength || (deferred.request.count == count ? (deferred.request.start || ) + count * : count), items: results };
},
_doQuery: function (args) {//重写了一个_doQuery
var query = typeof args.queryStr == 'string' ? args.queryStr : args.query;
//var myservice = this.service({}, args);
var myservice = this.service._getRequest({ operation: query.operation }, args)//从这里开始新的调用。
var xhrArgs = {
url: myservice.url,
handleAs: "json",
headers: {
Accept: "application/json,application/javascript",
Range: myservice.headers.Range
},
content: { filtercodtion: query.filtercodtion }
};
var deferred = dojo.xhrPost(xhrArgs); //rpcJsonRest.query(this.service, query, args);原来的调用。
var self = this;
if (this.loadReferencedSchema) {
deferred.addCallback(function (result) {
var contentType = deferred.ioArgs && deferred.ioArgs.xhr && deferred.ioArgs.xhr.getResponseHeader("Content-Type");
var schemaRef = contentType && contentType.match(/definedby\s*=\s*([^;]*)/);
if (contentType && !schemaRef) {
schemaRef = deferred.ioArgs.xhr.getResponseHeader("Link");
schemaRef = schemaRef && schemaRef.match(/<([^>]*)>;\s*rel="?definedby"?/);
}
schemaRef = schemaRef && schemaRef[];
if (schemaRef) {
var serviceAndId = rpcJsonRest.getServiceAndId((self.target + schemaRef).replace(/^(.*\/)?(\w+:\/\/)|[^\/\.]+\/\.\.\/|^.*\/(\/)/, "$2$3"));
var schemaDeferred = rpcJsonRest.byId(serviceAndId.service, serviceAndId.id);
schemaDeferred.addCallbacks(function (newSchema) {
lang.mixin(self.schema, newSchema);
return result;
}, function (error) {
alert(error);
console.error(error); // log it, but don't let it cause the main request to fail
return result;
});
return schemaDeferred;
}
return undefined;//don't change anything, and deal with the stupid post-commit lint complaints
});
}
return deferred;
}
});
}
);

解决问题的思路因为觉得太复杂[的确是复杂],而不知道怎么入手。要改变方法。耗的时间太久了。

上一篇:excel导出使用get请求参数过长问题


下一篇:欣赏<沉默的大多数>——王小波