Solution first
Make productOptionsa Objectinstead Arrayand use jQuery.extend()to combine productOptionswith the rest of the data that will be used in the ajax request.
var productOptions = new Object();
productOptions['color']="test1";
productOptions['size']="test2";
$.ajax({
type: "GET",
url: "test.js",
dataType: "script",
data: jQuery.extend({action: 'add'}, productOptions)
});
Productivity GET test.js?_=randomjQueryNumber&action=add&color=test1&size=test2
Long explanation
, , Array . , . (key, value).
,
1
var productOptions=new Array();
productOptions[0]="test1";
productOptions[1]="test2";
alert(productOptions.length);
: , , productOptions[0] productOptions[4], 5!
2
var productOptions=new Array();
productOptions['color']="test1";
productOptions['size]="test2";
alert(productOptions.length); //yields 0
1 productOptions[0]="test1"; productOptions.push("test1"); ( - 1 - push , ).
2 productOptions['color']="test1"; ""; , javascript-, color test1 .
, , javascript color size.
alert(productOptions.color);
alert(productOptions.size);
alert(productOptions[0]);
1. productOptions - , jQuery , option=test1&option=test2.
jQuery, option:productOptions option:new Array();