Reputation: 583
I am sending checked checkboxes value to php in array.
// tag =['Apple','Mango','Tomato']
var tag = $(this).children().siblings().children().children('input[name="cb"]:checked');
var tagData = [];
$.each(tag, function() {
tagData.push($(this).val());
});
console.log(tagData);
$.ajax({
type: "POST",
url: "script.php",
data: {tag: tagData },
cache: false,
success: function(){
alert("OK");
}
});
Console.log data
(2) ["Apple", "Apple"]
0: "Apple"
1: "Apple"
length: 2__proto__: Array(0)
I'm getting this array in php like this.
$list = $_POST['tag'];
$imgTag = implode( ", ",$list);
// i want like this - $imgTag = "Apple,Mango,Tomato".
But i getting empty line in php.
Upvotes: 0
Views: 46
Reputation: 8287
Serialize your tagData using JSON.stringify
while sending in ajax request. like this
$.ajax({
type: "POST",
url: "script.php",
data: {tag: JSON.stringify(tagData) },
cache: false,
success: function(){
alert("OK");
}
});
Upvotes: 1