Send array by GET

4

I am sending% of a array in JavaScript to another page via a GET by calling the function. The problem is that 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:

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

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

    
asked by anonymous 12.03.2015 / 17:07

1 answer

5

I can build logic to access the table I imagine coming 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 few 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

See working on ideone .

    
12.03.2015 / 17:47