发送数组 ajax.request 原型

send array ajax.request prototype

本文关键字:request 原型 ajax 数组      更新时间:2023-09-26

我被困在这里通过原型ajax.request方法向PHP脚本发送数组。

我的数组是构造的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_price值的索引号,tier_price这些索引号是01。这些不是我传递的实际索引,无论我构造什么索引,它都会从0重新索引它们。这对我来说没有用,因为我需要实际的索引 id 和值。

你应该使用哈希而不是数组。喜欢

attributeArray = {}