javascript – Send array by GET


I'm GET sending a JavaScript array to another page via a button calling the function. The problem is that when sending is in string and not in array . I want to pass this array to the Lua language. This array contains values. Example:

JavaScript code:

var position_x = new Array();
position_x = [50,80,110];

function btn_onclick() {
   window.location.href = "page.htm?positionX="+position_x;

<input type=button value=pass onclick="return btn_onclick()" />

On page 2:

for i=1, 3 do
    tabela[i] = GET["positionX"]

I want to go back to a table in Lua, because that way it inserts the three values ​​in each position.


I can set up the logic to access the table that I imagine comes from your page but it depends on which library is using to receive the data. I'm going to simulate the data received from the page in the first lines:

GET = {}
GET["positionX"] = "50,80,110"
-- o codigo acima nao estaria presente no script, foi so para simular o recebimento dos dados
i = 1
for palavra in string.gmatch(GET["positionX"], '([^,]+)') do
    tabela[i] = palavra
    i = i + 1
-- codigo so para mostrar o resultado no console, ele nao faz parte do script
for k, v in pairs(tabela) do print(k, v) end

See working on ideone . And on Also posted on GitHub for future reference .

Scroll to Top