【问题标题】:Sending a POST request from STORE从 STORE 发送 POST 请求
【发布时间】:2012-07-01 11:28:50
【问题描述】:

这是我的商店课程。我正在尝试完成 POST 请求。这是我的代码; 一切正常,当我从 Firebug 检查它时,我也得到了服务器响应。但唯一的问题是,当我在 firefox 中检查 Params tab 时,我看到 _dc 1341141752113 ,而当我在 firebug 中检查 Post tab 时,我看到了

limit   25
page    1
start   0

1.) 这些是我没有在我的代码中传递的一些参数。为什么我会得到这些?

Ext.define('Pro.store.Animal',{
    extend:'Ext.data.Store',
    model:'Pro.model.Animal',

    proxy: {
        actionMethods : {

            read   : 'POST'
        },
        type: 'ajax',
        url : '/projectmy/animal.php'

    }

    });

2.) 如果我想将参数传递给 PHP 文件,我应该如何编辑我的代码以传递参数?

【问题讨论】:

  • 您能否获得有关您的 2.) 的任何信息?我有同样的问题。我无法将任何参数传递给 PHP 脚本。
  • 看看我下面的回答,我已经为商店添加了代码。它应该可以帮助你。 (我假设您的 PHP 脚本没有问题)

标签: sencha-touch extjs4 extjs extjs-mvc extjs4.1


【解决方案1】:

这些参数是默认值。如果您使用分页工具栏或其他控件来浏览数据,则需要它们。 对于附加参数,您可以使用extraParams in your proxy

【讨论】:

  • 除了这个答案之外,_dc 是自动添加的“cache-busting”参数,以确保每次调用一个唯一的 url。请参阅 Ext.data.proxy.Server 类中的 noCache 参数。
【解决方案2】:
Ext.define('App.store.StoreName', {
    extend: 'Ext.data.Store',

    requires: [
        'App.model.StoreName'
    ],

    constructor: function(cfg) {
        var me = this;
        cfg = cfg || {};
        me.callParent([Ext.apply({
            storeId: 'stid',
            model: 'App.model.MyModel',
            proxy: {
                type: 'ajax',
                actionMethods: 'POST',
                api: {
                    read: '../myreadPhp.php',

                },
                reader: {
                    type: 'json'
                }
            },
            listeners: {
                beforeload: {
                    fn: me.onArraystoreBeforeLoad,
                    scope: me
                }
            }
        }, cfg)]);
    },

    onArraystoreBeforeLoad: function(store, operation, options) {
        this.proxy.extraParams.yournameparameter = "pass some name here"; 
        this.proxy.extraParams.yourageparamete = "pass your age here"; 
    }

});

myreadPhp.php 将期待参数 yournameparameteryourageparamete

【讨论】:

    猜你喜欢
    • 2020-10-28
    • 2012-12-04
    • 2011-01-20
    • 2020-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-17
    • 1970-01-01
    相关资源
    最近更新 更多