In HTML I have:
<input name="feature[1]" value="1" type="hidden">
<input name="feature[2]" value="1" type="hidden">
<input name="feature[3]" value="1" type="hidden">
And in Javascript I have:
features = $.map($('#add-place [name^="feature"]'), function(item, index)
{
if($(item).val()=='1')
{
return $(item).attr('name').replace(/[^0-9]/g, '');
}
});
When I console.log(features)
it returns an array but when I send it through ajax with new FormData
in PHP I will have an string containing the numbers in the features
array so if they are [1, 3]
I will get 1,3
as string in PHP.
What causes this?
EDIT
form = new FormData();
features = $.map($('[name^="feature"]'), function(item, index){if($(item).val()=='1'){return $(item).attr('name').replace(/[^0-9]/g, '');}});
form.append('features', features);
$.ajax({
url: url,
type: 'POST',
dataType: 'json',
enctype: 'multipart/form-data',
cache: false,
processData: false,
contentType: false,
data: form,
complete: function(response)
{
//
}
});