我试图在Luci中将数组从javascript发送到XHR.get请求。
var myarray[] has some contents . for example : `myarray[] = {"1","2","3"}` 我需要将这个数组作为参数传递给XHR.get请求。如何传递这个数组?
这是示例代码:
XHR.get('<%=REQUEST_URI%>', {status: 2,value: myarray},
function(x, info) {
if (!info) {
location.href=location.href;
}
else {
console.log("success");
}
}
);在Lua代码中,我收到了以下表单数据:
if luci.http.formvalue("status") == "2" then
local DetailValue[] = luci.http.formvalue("value")
local fileContent = {
content = "sample1",
find = "sample2"
}
luci.http.prepare_content("application/json")
luci.http.write_json(fileContent)
return
end但我正在犯错误。这是通过XHR.get发送数组的正确方式吗?有什么建议吗?
发布于 2017-10-17 00:07:51
下面是一个值的示例
XHR.get('<%=url('admin/services/sample')%>', { example : 'test' }, function(x) {
<do whatever>
});
function parse_gateway()
local example = luci.http.formvalue("example")
end当我试图用相同的键传入两个查询参数时,我得到了以下信息
XHR.get('<%=url('admin/services/sample')%>', { example : 'test', example : 'test1' }, function(x) {
<do whatever>
});
function parse_gateway()
local example = luci.http.formvalue("example")
end这次的例子是test1
因此,在您的情况下,您似乎需要有唯一的参数键。
XHR.get('<%=url('admin/services/sample')%>', { one : '1', two : '2', three : '3' }, function(x) {
<do whatever>
});
function parse_gateway()
local one = luci.http.formvalue("one")
local two = luci.http.formvalue("two")
local three = luci.http.formvalue("three")
end https://stackoverflow.com/questions/45304850
复制相似问题