问题描述
当Ext JS从休息的商店发出DELETE请求时,它包含一个实体主体。尽管此
Using this sample as reference:http://www.sencha.com/deploy/dev/examples/restful/restful.html
这是商店的定义:
var store = new Ext.data.Store({
id: 'user',
restful: true, // <-- This Store is RESTful
proxy: proxy,
reader: reader,
writer: writer
});
按删除按钮后,这是Ext JS发送的请求:
After pressing the "Delete" button, this is the request Ext JS sends:
DELETE http://www.sencha.com/deploy/dev/examples/restful/app.php/users/6 HTTP/1.1
Host: www.sencha.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; pt-BR; rv:1.9.2.4) Gecko/20100611 Firefox/3.6.4 (.NET CLR 3.5.30729)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: pt-br,pt;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Content-Type: application/json; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://www.sencha.com/deploy/dev/examples/restful/restful.html
Content-Length: 10
Cookie: bb_sessionhash=8d75f5e42d576fb695a02bf1d24c9ff1; etc...
{"data":6}
请求以此格式(与数据内容)提交到Google App Engine,它回复:
When a request in this format (with the "data" content) is submitted to Google App Engine, it replies with:
400 Bad Request
推荐答案
你可以解决这个问题,覆盖HttpProxy类中的一个方法。首先,添加以下代码:
You can fix this problem, as you guessed, by overriding a method in the HttpProxy class. First, add this code:
// Special HttpProxy that sends no body on DELETE requests
Ext.data.GAEHttpProxy = Ext.extend(Ext.data.HttpProxy, {
doRequest: function(action, rs, params, reader, cb, scope, arg) {
if(this.api[action]['method'].toLowerCase() == "delete") {
delete params.jsonData;
}
Ext.data.GAEHttpProxy.superclass.doRequest.call(this, action, rs, params, reader, cb, scope, arg);
}
});
然后,在你的其余代码中使用这个新类(GAEHttpProxy)而不是HttpProxy例如,当您创建在上面显示的商店中使用的代理时)。这对我有用,我希望它适合你!
Then, use this new class ("GAEHttpProxy") instead of HttpProxy in the rest of your code (for instance, when you create the proxy you use in your store shown above). This worked for me, and I hope it works for you!
这篇关于如何防止Ext JS使用休闲商店在DELETE请求中包含实体主体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!