I im building and array where my array key is from a variable like this:
var product_id = $('#product_id').val(); //22
var art = $('#article_id').val(); //229
var stk = $('#stk').val(); //20
var elements = [];
elements [art] = stk;
console.log(elements);
This is the result
Array[229]
228:"20"
length:229
__proto__:Array[0]
As you see the result, it actually created 229 array key,
When I make a AJAX POST with that variable. It post all 229 array item to it.
option[]:
option[]:
option[]:
option[]:
option[]:
option[]:
option[]:
option[]:
option[]:
option[]:
option[]:
option[]:20
It is possible I just want to post 1 key and value.
elements[229] = 20;
Not all the unused. Thanks!
Below is my ajax call
$.ajax({
url: 'product/getprice',
type: 'post',
data: { product_id: product_id, option: element },
dataType: 'text',
beforeSend: function() {
},
complete: function() {
},
success: function(json) {
json = JSON.parse(json);
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});

