我有这个 ajax 表单,最后我有一个数组中的值。代码在下面..但我在这些项目的 php 响应中一直为空。我想我做这个 .ajax 调用是错误的,任何想法都会有很大帮助。我也不知道在 .ajax 调用的成功部分写什么。那是我想念的吗?请看下面:
$('#submit_third').click(function(){
//update progress bar
$('#progress_text').html('100% Complete');
$('#progress').css('width','339px');
//prepare the fourth step
var fields = new Array(
$('#usernameReg').val(),
$('#passwordReg').val(),
$('#email').val(),
$('#firstname').val(),
$('#lastname').val(),
$('#city').val(),
$('#phone').val(),
categoryResult,
$("#msg").val()
);
var tr = $('#fourth_step tr');
tr.each(function(){
//alert( fields[$(this).index()] )
$(this).children('td:nth-child(2)').html(fields[$(this).index()]);
});
//slide steps
$('#third_step').fadeOut(1000);
$('#fourth_step').delay(1000).fadeIn(1000);
$('#submit_fourth').click(function(){
//send information to server
console.log(fields);
$.ajax({
type: "POST",
data: 'fields',
dataType: 'json',
url: "php/postEngine.php",
success: function(html){
}
});
});
});
php 信息(我正在使用蓬勃发展:
include_once($_SERVER['DOCUMENT_ROOT'] . '/../inc/init.php');
include_once($_SERVER['DOCUMENT_ROOT'] . '/dev/form_data.php');
include_once($_SERVER['DOCUMENT_ROOT'] . '/dev/db_handling.php');
ini_set('display_errors', 'On');
try {
$tbl_user = 'tbl_users';
$statement = $db->prepare("INSERT INTO $tbl_user
(username,
email,
firstname,
lastname,
city,
phone)
VALUES
(%s,
%s,
%s,
%s,
%s,
%s
)"
);
$db->query($statement,
$un,
$email,
$firstname,
$lastname,
$city,
$phone
);
// Update of Email_Replied to 1
//$db->execute("UPDATE accommodation SET Email_Replied = '1' WHERE ID = %i", $user_id);
} catch (Exception $e) {
echo $error_msg;
echo $un;
echo $email;
echo $firstname;
echo $lastname;
echo $city;
echo $phone;
echo json_encode($un);
$error_msg = 'An error occured on postEngine.php';
}
?>
$un = fRequest::get('fields[0]');
$email = fRequest::get('fields[2]');
$firstname = fRequest::get('fields[3]');
$lastname = fRequest::get('fields[4]');
$city = fRequest::get('fields[5]');
$phone = fRequest::get('fields[6]');
?>