Send array by GET

Asked

Viewed 1,541 times

4

I’m sending by GET one array in Javascript to another page through a button calling the function. The problem is that sending is in string and not in array. I want to pass this array for 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:

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

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

  • What library for web manipulation are you using? IE, how is this coming GET?

  • Comes through the address bar, I can see the values passed in parameter.

  • But this GET does not appear out of nowhere in Lua, needs some library, which one is using?

1 answer

5


I can assemble the logic to access the table that I imagine comes from your page but this depends on which library you are using to receive the data. I will 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
tabela={}
i = 1
for palavra in string.gmatch(GET["positionX"], '([^,]+)') do
    tabela[i] = palavra
    i = i + 1
end
-- 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

Behold working in the ideone. And in the repl it.. Also put on the Github for future reference.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.