2011-07-31 20 views
0

你好!我想在一個帖子查詢中發送幾次變量(每次使用不同的值)。 在HTML形式,它的工作原理,看起來像:加速器發佈請求。在一個請求中發送一個變量幾次。

<form method="POST" action="http://localhost/index.php"> 
    <input type="hidden" name="line_item" value="value1"> 
    <input type="hidden" name="line_item" value="value2"> 
    <input type="hidden" name="line_item" value="value3">  
</form> 

但Appcelerator的這個代碼僅發送最後一個值:

var httpClient = Titanium.Network.createHTTPClient(); 
    var params = { 
      line_item:'value1', 
      line_item:'value2', 
      line_item:'value3', 
    }; 
httpClient.open('POST', 'http://localhost/index.php'); 
httpClient.send(params); 

誰能幫助?謝謝。

對不起,我忘了提及我沒有訪問服務器,我需要它在appcelerator中解決。

回答

0

如果你使用PHP作爲服務器平臺,您可以加入POST變量數組

<form method="POST" action="http://localhost/index.php"> 
    <input type="hidden" name="line_item[]" value="value1"> 
    <input type="hidden" name="line_item[]" value="value2"> 
    <input type="hidden" name="line_item[]" value="value3">  
</form> 

,然後在PHP程序像數組:

if (is_array($_POST['line_item[]'])) { 
    $count = 0; 
    foreach($_POST['line_item[]'] as $line_item) 
    echo($line_item . " #" . $count++); 
} 
+0

對不起,我忘了提及我沒有訪問服務器,我需要它在appcelerator中解決。 – user837488

0

解決...

var httpClient = Titanium.Network.createHTTPClient(); 
httpClient.open('POST', 'http://localhost/index.php'); 
httpClient.send("line_item=value1&line_item=value2&line_item=value3");