开发者

jquery load data

dumbest questio开发者_如何学Cn ever... but I want to somehow fill 'gid' value in data load

gid  = 123;
from = 33;
to   = 44;

$('#x').load('y', {'range['+gid+'][]' : [from , to]});

so I could get

[range] => Array
        (
            [123] => Array
                (
                    [0] => 33
                    [1] => 44
                )

        )

but with this syntax 'range['+gid+'][]' I get 'missing : after property id'. I'm desperate...


You can't use calculated property names for the left-hand side of an initializer in an object literal. So instead of:

$('#x').load('y', {'range['+gid+'][]' : [from , to]});

do this:

var options = {};
options['range['+gid+'][]'] = [from , to];
$('#x').load('y', options);

...because you can use calculated property names with the [] notation for setting object properties.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜