2

In 3 different AJAX scripts that I have written the error message is displayed even though the ajax is processes the PHP file updated and all the success statements are executed. Since I only discovered ajax a few days ago. There must be something wrong with my scripts. Perhaps someone could see where I have gone wrong.

AJAX:

function bookingdetails() {
    var actdate = $('#actdate').val();
    var airport = $('#FLTairport').val();
    var number = $('#FLTnumber').val();
    var time = $('#FLTtime').val();

    var dataString = 'actdate=' + actdate + '&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="30" height="30"/>');
                 },
                  error: function() {
                 $('#airloader').html('arse up');
                 },
                 dataType:'json',
             success: function(data) {
     $('#actdate').val(data.date);
     $('#FLTnumber').val(data.FLTnumber);
     $('#airloader').html('marvellous');
     $('#FLTairport').val(data.FLTairport);
     $('#FLTdate').val(data.FLTdate);
     $('#FLTtime').val(data.FLTtime);
     $('#datediv').load('<?php echo $thisposturl;?> #datediv');
}


        });

}

PHP : (dont worry about the insert post bits)

<?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['actdate'],
);
 $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');
$actdate = get_the_time('Y-m-d');
$FLTairport = $_POST['airport'];
$FLTnumber = $_POST['number'];
$FLTtime = $_POST['time'];

echo json_encode( array('FLTdate'=>$FLTdate, 'actdate'=>$actdate, 'FLTairport'=>$FLTairport, 'FLTnumber'=>$FLTnumber, 'FLTtime'=>$FLTtime));
?>

Result all values are updated but it still displays 'arse up' in the #airloader. This is one example I can provide it with 3 out of 4 of the ajax scripts that I have written.

Any ideas?

Marvellous

Walrus
  • 19,801
  • 35
  • 121
  • 199
  • 1
    what error message do you get – S L Mar 09 '11 at 11:38
  • 1
    Follow the advice in http://stackoverflow.com/questions/377644/jquery-ajax-error-handling-show-custom-exception-messages to see exactly what error response you are getting. – Blair McMillan Mar 09 '11 at 11:42
  • You sure there isn't a typo in your html for the `airloader` element? – jswolf19 Mar 09 '11 at 13:37
  • @experimentx No error message, I get the error attribute from the ajax call in this case 'arse up' ... @jswolf19 no typo. – Walrus Mar 10 '11 at 08:30
  • so what response are you getting at your firebug console – S L Mar 10 '11 at 08:41
  • 1
    The error callback accepts three arguments `error(jqXHR, textStatus, errorThrown)` add'em to you error callback and print textStatus instead 'arse up' so we can see more info about the error. – Terseus Mar 10 '11 at 08:45
  • Using the technique in the comment above the returning error is parsererror – Walrus Mar 11 '11 at 09:10
  • agree: find out what error is getting thrown. Also, if you use firebug or chrome dev tools look at the xhr request and you can see what http response it gave, if it'a anything other than a 200 the error function would be getting called – Anony372 Mar 12 '11 at 16:36
  • if you figure it out don't forget to post what the error was back here so the community can benefit too :D – Anony372 Mar 12 '11 at 16:37

1 Answers1

0

Have you checked the second parameter to your error function?

See: http://api.jquery.com/jQuery.ajax/

error(jqXHR, textStatus, errorThrown) ..., a string describing the type of error that occurred and an optional exception object, if one occurred. Possible values for the second argument (besides null) are "timeout", "error", "abort", and "parsererror". ...

yoshi
  • 14