ExtJs 4.1:如何使用Ext.Ajax.request()在请求体中发送json数据?

lea*_*eaf 10 ajax extjs request extjs4.1

我想发送json数据,Ext.Ajax.request()然后在ASP.NET中使用Request.InputStream它来访问它,这是请求体的内容.我需要一种方法告诉ExtJs在使用时完成请求体中的数据写入Ext.data.proxy.Ajax.

Aci*_*ier 25

指定POST方法,只需使用请求的jsonData配置:

Ext.Ajax.request({
    url: 'myUrl',
    method: 'POST',
    params: {
        requestParam: 'notInRequestBody'
    },
    jsonData: 'thisIsInRequestBody',
    success: function() {
        console.log('success');
    },
    failure: function() {
        console.log('woops');
    }
});
Run Code Online (Sandbox Code Playgroud)

如果你想要一个写成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');
    }
});
Run Code Online (Sandbox Code Playgroud)