10

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

4

1 回答 1

27

指定POST方法并仅使用请求的jsonData配置:

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

如果您想要以 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');
    }
});
于 2012-09-17T17:04:01.527 回答