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

10

我想使用Ext.Ajax.request()发送JSON数据,然后在ASP.NET中使用Request.InputStream来访问请求主体的内容。我需要一种方法告诉ExtJs将数据写入请求主体,就像使用Ext.data.proxy.Ajax时所做的那样。

1个回答

29

指定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');
    }
});

太好了!写入选项是锦上添花的! - user1636522

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接