【问题标题】:ExtJs 4.1 : How to send json data in the request body using Ext.Ajax.request()?ExtJs 4.1:如何使用 Ext.Ajax.request() 在请求正文中发送 json 数据?
【发布时间】:2012-09-09 21:59:22
【问题描述】:

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

【问题讨论】:

    标签: ajax extjs request extjs4.1


    【解决方案1】:

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

    【讨论】:

    • 太棒了!作家选项是锦上添花!
    猜你喜欢
    • 1970-01-01
    • 2015-02-25
    • 1970-01-01
    • 2017-05-15
    • 2017-05-04
    • 2013-10-07
    • 2017-11-02
    • 2020-05-23
    • 1970-01-01
    相关资源
    最近更新 更多