ExtJS Ajax POST与代理POST

问题描述 投票:4回答:2

我正在尝试使用ExtJS 4.1创建一个网格面板。它使用AJAX代理从服务器获取数据:

var store = Ext.create('Ext.data.Store', {
    model: 'myModel',
    pageSize: pageSize,
    proxy: {
        type: 'ajax',
        url: "../search",
        actionMethods:  {
            create: "POST",
            read: "POST",
            update: "POST",
            destroy: "POST"
        },
        headers: {
            'Content-Type': 'application/json'
        },
        limitParam: false,
        startParam: false,
        pageParam: false,
        extraParams: JSON.stringify({
            rows: pageSize,
            role: "Admin",
            index: myIndex,
            question: searchPhrase
        }),
        reader: {
            type: 'json',
            root: 'results.results',
            totalProperty: 'numFound',
            model: 'myModel'
        }
    }
});

store.loadPage(1);

但它似乎没有用。

我收到一条错误消息,指出无法读取JSON。更重要的是,在Firebug中,发送的参数不是人类可读的。

当我尝试使用相同的参数进行Ajax调用时,一切似乎都没问题:

Ext.Ajax.request({
    url:"../search",
    method: "POST",
    params: JSON.stringify({
        rows: pageSize,
        role: "Admin",
        index: myIndex,
        question: searchPhrase
    }),
    success: function(){
        console.log("ok");
    },
    failure: function(response, opts){
        console.log("failed");
    },
    headers: {
        'Content-Type': 'application/json'
    }
});

即使在Firebug中,请求中的每个参数也都很好。

使用代理时框架有什么不同?

javascript extjs4.1
2个回答
0
投票

这似乎是另一个ExtJS问题。

我在这里找到了一个修复:

http://www.sencha.com/forum/showthread.php?196194-Ajax-Store-Send-Params-as-JSON-Body


0
投票

我为商店使用以下代理配置(ExtJS v6.5.2):

proxy: {
    url: 'api/search',
    paramsAsJson: true,
    actionMethods: {
        read: 'POST'
    },
    type: 'ajax',
    reader: {type: 'json'}
},

它将参数发送为JSON:

{"page":1,"start":0,"limit":25}
© www.soinside.com 2019 - 2024. All rights reserved.