ExtJs 4.1:如何使用 Ext.Ajax.request() 在请求正文中发送 json 数据?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12463442/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ExtJs 4.1 : How to send json data in the request body using Ext.Ajax.request()?
提问by leaf
I would like to send json data using Ext.Ajax.request()then access it in ASP.NET using Request.InputStreamwhich is the content of the request body. I need a way to tell ExtJs to write the data in the request body as it is done while using an Ext.data.proxy.Ajax.
我想发送 json 数据,Ext.Ajax.request()然后使用它在 ASP.NET 中访问它,使用Request.InputStream它是请求正文的内容。我需要一种方法来告诉 ExtJs 将数据写入请求正文中,因为它是在使用Ext.data.proxy.Ajax.
回答by vanderwyst
Specify POSTmethod and just use the request's jsonDataconfig:
指定POST方法并只使用请求的jsonData配置:
Ext.Ajax.request({
url: 'myUrl',
method: 'POST',
params: {
requestParam: 'notInRequestBody'
},
jsonData: 'thisIsInRequestBody',
success: function() {
console.log('success');
},
failure: function() {
console.log('woops');
}
});
If you want a recordwritten as JSON you can use a JSON writer like this also.
如果您想要将记录写为 JSON,您也可以使用这样的 JSON 编写器。
var writer = Ext.create('Ext.data.writer.Json'),
record = Ext.getStore('SomeStoreID').first();
Ext.Ajax.request({
url: 'myUrl',
method: 'POST',
params: {
requestParam: 'notInRequestBody'
},
jsonData: writer.getRecordData(record),
success: function() {
console.log('success');
},
failure: function() {
console.log('woops');
}
});

