如何在Luci Openwrt中通过XHR.get请求传递数组?

我正在尝试从JavaScript发送数组到Luci Openwrt的XHR.get请求中。

var myarray[] 有一些内容。例如: `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发送数组的正确方式吗?有什么建议吗?

点赞
用户2976939
用户2976939

以下为示例,仅展示一个值:

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

这次,example 的值为 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
2017-10-17 00:07:51