gpt4 book ai didi

jquery - 在perl cgi脚本中迭代动态数组

转载 作者:行者123 更新时间:2023-12-01 00:26:59 24 4
gpt4 key购买 nike

我通过jquery传递

$.ajax({
'type' : 'POST',
'data' : {
'foo': {
'foo1':'bar1,
'foo2':'bar2'
}
},
'async' : false,
'global' : false,
'url' : "path/to/script.pl",
'dataType' : "json",
'success' : function(data) {
json = data;
},
'error' : function(jqxhr, textStatus, error) {
console.log("Request Failed: " + textStatus);
console.log(error);
}
});

到我的cgi脚本。

HTML 参数:foo%5Bfoo1%5D=bar1&foo%5Bfoo2%5D=bar2

我无法通过使用 $cgi->param('foo[]')foo 用作数组

CGI::param called in list context from package main line 30, this can lead to vulnerabilities. See the warning in "Fetching the value or values of a single named parameter

我似乎所有数组元素都被硬编码到像“foo[foo1]”这样的参数中。

是否可以获得动态访问?

use Data::Dumper 的输出;打印转储器标量 $cgi->Vars();

$VAR1 = bless( {
'use_tempfile' => 1,
'.fieldnames' => {},
'.charset' => 'ISO-8859-1',
'.parameters' => [
'foo[foo1]',
'foo[foo2]'
],
'escape' => 1,
'param' => {
'foo[foo2]' => [
'bar2'
],
'foo[foo1]' => [
'bar¹'
]
}
}, 'CGI' );

最佳答案

您必须以 json 字符串形式发送数据

    'data' : JSON.stringify({
'foo': {
'foo1':'bar1',
'foo2':'bar2'
}
}),

并在服务器端将字符串转换为 native perl 结构,

use JSON;
my $data = decode_json( $cgi->param('keywords') );

关于jquery - 在perl cgi脚本中迭代动态数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31336208/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com