我正在尝试使用 $_POST 将数组发送到 php 文件,但仍然总是得到一个未定义的变量!
var all = [];
var textInput = $('input[type=text]');
var checkBox = $('input[type=checkbox]');
var radio = $('input[type=radio]');
textInput.each(function () {
if ($(this).val() != "") {
name = $(this).attr('name');
value = $(this).attr('value');
all[name] = value;
}
});
checkBox.each(function () {
if ($(this).attr("checked")) {
name = $(this).attr('name');
value = $(this).attr('value');
all[name] = value;
}
});
radio.each(function () {
if ($(this).attr("checked")) {
name = $(this).attr('name');
value = $(this).attr('value');
all[name] = value;
}
});
var getSelect = $('#experince');
if (getSelect[0].selectedIndex != 0) {
name = getSelect[0].name;
value = getSelect[0].selectedIndex;
all[name] = value;
}
$.post('test.php', all, function (data) {
alert(data);
$.each(data, function (key, value) {
alert(value);
});
}, 'json');
PHP文件
if(!isset($_POST['workF'])){
$_POST['workF'] ="undefine";
}
if(!isset($_POST['workP'])){
$_POST['workP']="undefine";
}
if(!isset($_POST['gender'])){
$_POST['gender']="undefine";
}
if(!isset($_POST['experince'])){
$_POST['experince']="undefine";
}
if (!isset($_POST['jobs'])){
$_POST['jobs']="undefine";
}
if(!isset($_POST['location'])){
$_POST['location']="undefine";
}
$work_type_f = $_POST['workF'];
$work_type_p = $_POST['workP'];
$gender = $_POST['gender'];
$experince = $_POST['experince'];
$jobs = $_POST['jobs'];
$location =$_POST['location'];