dtxw20878 2015-12-03 16:42
浏览 79
已采纳

ExtJS 4:将复杂数据发送到服务器并在新的浏览器窗口中打开结果

I want to generate an .xlsx file on the server (using PHP if it metters) and open result (actually 'Save As...' window) in a new browser window. To generate file on the server I have to pass complex data (file settings) like:

[
    {
        'value1': 1,
        'value2': 2,
        'value3': 3
    },
    {
        'value4': 4,
        'value5': 5,
        'value6': 6
    }    
 ]

For this I doing something like:

Ext.create(Ext.form.Panel).submit({
    clientValidation: false,
    method: 'POST',
    params: [
        {
            'value1': 1,
            'value2': 2,
            'value3': 3
        },
        {
            'value4': 4,
            'value5': 5,
            'value6': 6
        }    
    ],
    standardSubmit: true,
    target: '_blank',
    url: 'my/real/url'
});

But on my server I keep getting wrong data, like

Array (
    [0] => [object Object]
    [1] => [object Object]
)

in my $_POST (where [object Object] is actual string) or

0=%5Bobject+Object%5D&1=%5Bobject+Object%5D

in my $data (Im using Slim framework)

$app->post('my/real/url', function () use ($app) {
    $request = $app->request();
    $data = $request->getBody();
});

Actually I tried many workarounds but I never get required data on my server side. Maybe I using wrong approach or just do it wrong?

  • 写回答

1条回答 默认 最新

  • duanjing7651 2015-12-03 21:51
    关注

    The reason is standardSubmit config will cause Ext JS to create a <form> and add items to that form with the values of the form items and the params you pass in. A <form> item cannot contain complex values like arrays or objects.

    You can encode your data before it's sent and then on the server decode it:

    Ext.create(Ext.form.Panel).submit({
        clientValidation: false,
        method: 'POST',
        params: {
            data: Ext.encode([
                {
                    'value1': 1,
                    'value2': 2,
                    'value3': 3
                },
                {
                    'value4': 4,
                    'value5': 5,
                    'value6': 6
                }    
            ])
        },
        standardSubmit: true,
        target: '_blank',
        url: 'my/real/url'
    });
    

    Then on your server, not sure about Slim framework (never used it), but with PHP you can use json_decode:

    $data = json_decode($_POST['data']);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 carsim与simulink联合方针模拟无控制器驾驶员驾驶效果
  • ¥25 annaconda jvpyter
  • ¥20 来一个会抓包app支付接口的
  • ¥30 vivado2017.4的sdk打不开
  • ¥50 matlab,文献复现
  • ¥20 寻找Flink CDC指导,有偿咨询
  • ¥15 cruise如何仿真不同温度下车辆的经济性?
  • ¥20 扑克牌游戏的完整代码
  • ¥88 求帮安装Python架构的vnpy
  • ¥20 逻辑回归法分析品牌知名度和购买意向