2012-08-13 64 views
0

我卡在這裏通過原型ajax.request方法發送數組到PHP腳本。發送數組ajax.request原型

我的數組構造JavaScript的一面:它喜歡這樣

attributeArray = new Array(); 

//This line of code is actually inside a loop 
attributeArray[id] = value; 
//loop end 
new Ajax.Request(reloadurl, { 
    method: 'post', 
    parameters: {'id[]':attributeArray}, 
    onComplete: function(transport) { 
    $('load-map-fields').innerHTML = ""; 
    $('load-map-fields').innerHTML = transport.responseText; 

    } 
    }); 

,並在PHP腳本我得到這個數組

Array ([id] => Array ([0] => special_price [1] => tier_price)) 

通告值special_pricetier_price這些都是指數01。這些不是我通過的實際索引,無論我構建的索引如何,它都從0重新索引它們。這對我無用,因爲我需要實際的索引ID以及值。

+2

你剛剛嘗試'參數:attributeArray' ?? – 2012-08-13 14:02:13

+0

http://api.jquery.com/jQuery.post/將節省您的時間 – 2012-08-13 14:06:30

+0

@BrianGlaz:是的,它可以工作,但我想用一個父數組綁定這個數組。 – Daric 2012-08-17 08:20:57

回答

0

你應該使用散列而不是數組。像

attributeArray = {} 
+0

現在,在PHP腳本$ _POST中不包含任何內容 – Daric 2012-08-13 14:07:42

+0

正如我所知,原型可以發送哈希值。所以只需要像參數那樣做:attributeArray或者參數:{id:attributeArray} – Ximik 2012-08-13 15:14:58