我正在使用以下ajax更新頁面上的信息,然後將頁面重新提交到數據庫中。該腳本每次都在Error參數處停止失敗。任何人都可以看到我出錯的地方。用於更新頁面失敗的AJAX
AJAX -
function bookingdetails() {
var date = <?php the_time('Y-m-d');?>;
var airport = $('#FLTairport').val();
var number = $('#FLTnumber').val();
var time = $('#FLTtime').val();
var dataString = 'date=' + date + '&airport=' + airport + '&number=' + number + '&time=' + time;
$.ajax({
type: 'POST',
url: '<?php echo $thisposturl;?>?update',
data: dataString,
beforeSend: function() {
$('#airloader').html('<img id="BKloader" src="http://www.divethegap.com/update/z-images/structure/icons/blockloader.gif" alt="" width="40" height="30"/>');
},
error: function() {
$('#airloader').html('Failed to update booking, try again');
},
dataType:'json',
success: function(data) {
$('#date').val(data.date);
$('#FLTnumber').val(data.FLTnumber);
$('#airloader').val(data.FLTnumber);
$('#FLTairport').val(data.FLTairport);
$('#FLTdate').val(data.FLTdate);
$('#FLTtime').val(data.FLTtime);
}
});
}
PHP -
<?php
function __update_post_meta($post_id, $field_name, $value = '')
{
if (empty($value) OR ! $value)
{
delete_post_meta($post_id, $field_name);
}
elseif (! get_post_meta($post_id, $field_name))
{
add_post_meta($post_id, $field_name, $value);
}
else
{
update_post_meta($post_id, $field_name, $value);
}
}
if (is_user_logged_in()) {
$my_post = array(
'ID' => get_the_ID(),
'post_date' => $_POST['date'],
);
$the_post_id = wp_update_post($my_post);
__update_post_meta($the_post_id, 'FLTairport', $_POST['airport']);
__update_post_meta($the_post_id, 'FLTnumber', $_POST['number']);
__update_post_meta($the_post_id, 'FLTtime', $_POST['time']);
}
$FLTdate = get_the_time('d/m/Y');
$date = get_the_time('Y-m-d');
$FLTairport = $_POST['airport'];
$FLTnumber = $_POST['number'];
$FLTtime = $_POST['time'];
echo json_encode(array('FLTdate'=>$FLTdate, 'date'=>$date, 'FLTairport'=>$FLTairport, 'FLTnumber'=>$FLTnumber, 'FLTtime'=>$FLTtime));
?>
任何想法?
非凡
爲什麼在網址的末尾添加'?update'? – jondavidjohn 2011-03-03 14:05:56
這是PHP文件的位置,由另一個使用include函數引用頁面的腳本確定 – 2011-03-03 14:13:17