I tried to create an array with serializeArray and post it to php. but my code doesn't work. I read this questions (question) but I didn't understand my mistake yet.
this is my ajax code
var str = $("form").serializeArray();
$.ajax({
type: "POST",
url: "myfile.php",
data: str,
success: function (value) {
$("#mydata").html(value);
}
});
HTML Code
<form>
<select name="num0">
<option value="">num0</option>
<option value="12">12</option>
<option value="13">13</option>
</select>
<select name="num1">
<option value="">num2</option>
<option value="123">123</option>
<option value="133">133</option>
</select>
<select name="num2">
<option value="">num3</option>
<option value="12345">12345</option>
</select>
</form>
PHP Code
$postarr = array();
$num=$_POST['num0'];
$postarr[]=$num;
$num=$_POST['num1'];
$postarr[]=$num;
$num=$_POST['num2'];
$postarr[]=$num;
it giving me the following error message:
Notice: Undefined index: num0 (and same message for other variables).
By the way, English is not my native language; please excuse typing errors.