JQuery的发送时删除空数组 [英] JQuery removes empty arrays when sending

查看:125
本文介绍了JQuery的发送时删除空数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code:

$.post('block_ajax.php'
    ,   {   'action': 'set_layout'
        ,   'listid': 123
        ,   'layout': []
        }
    ,   function(data) {
            // ...
        }
);

在recieving脚本(block_ajax.php)只有临危的行动和listid参数。当我检查什么使用Chrome发送,我看到了布局参数甚至没有发送到后端脚本。

The recieving script (block_ajax.php) only recieves the "action" and "listid" parameters. When I inspect what is sent using Chrome, I see the "layout" parameter isn't even send to the backend script.

由于是一个空数组,并没有一个数组之间的区别,我想有JQuery的发送空数组。我可以找到一些迹象表明,JQuery的(1.6.1),似乎要做到这一点,而不是如何这样做停止它。 JSON格式允许空数组和空对象,所以我想应该是可以的。

Since there is a difference between an empty array and the absence of an array, I'd like to have JQuery send the empty array. I can find some indications that JQuery (1.6.1) seems to do this, but not how to stop it from doing so. JSON format allows for empty arrays and empty objects, so I think it should be possible.

有谁知道该怎么改变这样的JQuery可以发送空数组?

Does anybody know what to change so JQuery can send empty arrays?

推荐答案

我不知道为什么你需要发送一个空白的参数。仅仅检查PHP脚本的参数是否存在应该够了。但是,如果你真的想这样做,使用'布局':[] 而不是布局:[] 。该参数应被发送。

I am not sure why you need to send a blank parameter. Merely checking the existence of the parameter in the PHP script should be enough. However, if you really want to do it, use 'layout': [""] instead of 'layout': []. The parameter should be sent.

(另外,你可能要重新命名布局布局[] 来表明它是一个数组,但这是不必要的。)

(In addition, you might want to rename layout to layout[] to indicate it's an array, but this is unnecessary.)

这篇关于JQuery的发送时删除空数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆