0

我正在尝试将值传递给 PHP 服务器端。我的商店代码如下;

Ext.define('MyApp.store.MyArrayStore', {
    extend: 'Ext.data.Store',

    requires: [
        'MyApp.model.MyMOD'
    ],

    config: {
        autoLoad: true,
        model: 'MyApp.model.MyMOD',
        storeId: 'MyArrayStore',
        proxy: {
            type: 'ajax',
            actionMethods: 'POST',
            url: 'http://localhost/mm/app/php/res.php',
            reader: {
                type: 'json'
            }
        },
        listeners: [
            {
                fn: 'onArraystoreBeforeLoad',
                event: 'beforeload'
            }
        ]
    },

    onArraystoreBeforeLoad: function(store, operation, eOpts) {
        this.proxy.extraParams.VALUES1 = "pass some name here"; 
    }

});

PHP 代码

<?php
error_reporting(E_ERROR | E_PARSE);

require_once 'conn.php'; // contains the connection

$v = $_POST['VALUES1'];
echo json_encode($v);

?>

返回的是null,而不是我从商店传递的值(即pass some name here)。

我该如何纠正这个?

更新

Request URL:http://localhost/test/app/php/res.php?_dc=1373343459447
Request Method:POST
Status Code:200 OK
Request Headersview source
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:23
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Host:localhost
Origin:http://localhost
Referer:http://localhost/test/app.html
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36
X-Requested-With:XMLHttpRequest
Query String Parametersview sourceview URL encoded
_dc:1373343459447
Form Dataview sourceview URL encoded
page:1
start:0
limit:25
Response Headersview source
Connection:Keep-Alive
Content-Length:24
Content-Type:text/html
Date:Tue, 09 Jul 2013 04:17:39 GMT
Keep-Alive:timeout=5, max=96
Server:Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_perl/2.0.4 Perl/v5.10.1
X-Powered-By:PHP/5.3.1
4

2 回答 2

2

您需要更改设置 extraParams 的方式。在这种情况下,我将使用

  store.getProxy().setExtraParam('VALUES1','pass some name here');

如果您需要发送多个参数,请使用 setExtraParams

  var param = { VALUES1: 'param1', VALUES2 : 'param2'};
  store.getProxy().setExtraParams(param);

如此完整的商店代码

Ext.define('MyApp.store.MyArrayStore', {
    extend: 'Ext.data.Store',

    requires: [
        'MyApp.model.MyMOD'
    ],

    config: {
        autoLoad: true,
        model: 'MyApp.model.MyMOD',
        storeId: 'MyArrayStore',
        proxy: {
            type: 'ajax',
            actionMethods: 'POST',
            url: 'http://localhost/mm/app/php/res.php',
            reader: {
                type: 'json'
            }
        },
        listeners: [
            {
                fn: 'onArraystoreBeforeLoad',
                event: 'beforeload'
            }
        ]
    },

    onArraystoreBeforeLoad: function(store, operation, eOpts) {
        store.getProxy().setExtraParam('VALUES1 ','pass some name here');
    }

});
于 2013-07-08T17:17:08.927 回答
1

而不是this.proxy尝试this.getProxy()

我发现控制台对这类事情非常有用。在我自己的应用程序中运行Ext.getStore('MyStore').proxy;让我不确定,而Ext.getStore('MyStore').getProxy()让我得到我的代理。

使用控制台,对我来说它是 API 之后最有价值的开发工具。

祝你好运,布拉德

于 2013-07-08T16:27:47.787 回答