ds342222 2014-01-28 15:16
浏览 43

将带有ajax的数组传递给服务器

I try to pass ids as array via ajax but when I dump out the get variable on server side with PHP I do not get any values, the array is empty. Debugging with firebug I see that the array is getting passed but [] is encoded ids%5B%5D

my javascript

  function update_category(selected) {
        $.ajax({
            url: '/admin/?controller=products&action=update_category',
            type: 'GET',
            dataType: "application/JSON",
            data: {
                ids: cat_ids,
                s_category: selected
            },
            success: function(data) {
                addAlert('alert-'+data, data);
            },
            error: function(data) {
                addAlert('alert-'+data.responseText, data.responseText);
            }
        });
    }

var_dump $_GET['ids'] null dumping the hole $_GET I get ["ids%5B%5D"]

I do not understand why the array is getting encoded on submit in linux environment

Under ubuntu 12.10 PHP 5.3.10 Firebug XHR->PARAMS

  action    update_category
    controller  products
    ids%5B%5D   1403172219
    ids%5B%5D   1530542001
    s_category  1

how to pass properly the array?

  • 写回答

1条回答 默认 最新

  • dongyi5070 2014-01-28 15:18
    关注

    Since you are already passing GET values int he URL here:

    /admin/?controller=products&action=update_category

    Then the information in data probably never passes.

    Try this instead:

      function update_category(selected) {
            $.ajax({
                url: '/admin/',
                type: 'GET',
                dataType: "application/JSON",
                data: {
                    ids: cat_ids,
                    s_category: selected,
                    controller: 'products',
                    action: 'update_category'
                },
                success: function(data) {
                    addAlert('alert-'+data, data);
                },
                error: function(data) {
                    addAlert('alert-'+data.responseText, data.responseText);
                }
            });
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏