alwaysLearn
alwaysLearn

Reputation: 6950

Why ajax request is getting aborted ....?

I am sending ajax request to server

$.ajax({
    type: "POST",
    data: checkin_push,
    url: api_url + 'file.php?token=' + last_token + '&date=' + dated,
    dataType: "json",
    timeout: 100000, // 100 seconds
    success: function(data) {
        // invoke sync
        api_pending_sync = true;            
        // checkin back to home
        $.mobile.changePage('#home', { reverse: true });
        //api_sync_message
        $('#sync-message').fadeIn(300).html('<div class="ui-body ui-body-e ui-corner-all" style="margin-bottom: 20px;" data-theme="d">Successfully checked in for ' + checkin_display_date() + '.</div>').fadeOut(5000);
    },
    complete: function(jqXHR, textStatus) {
        $.mobile.hidePageLoadingMsg();
    },
    error: function() {
        $('#checkin-status-message').fadeIn(300).html('<div class="ui-body ui-body-e ui-corner-all" style="margin-bottom: 20px; color: red;" data-theme="d">Unable to Check In, Please check your internet connection and try again.</div>').fadeOut(5000);
    }
});

Here is relevant code of file.php

     =========rest code -=================

    #------------------- send alert to life lines (send alerts) -------------------

$query = query("SELECT email, phone, sms_carrier FROM table WHERE account_id = ".escape($account_id));
if ((mysqli_num_rows($query) > 0) and $send_alert) 
{
   while ($l = mysqli_fetch_assoc($lifelines)) 
   {

           // send mail 
           /* this function is returning value of mail() function*/
       send_alert_email($userEmail, $sms_email, 'alert-2');

   }
}
#-------------------------------(/alerts)--------------------------------------

$return = array('answers' => $answers); //, 'transact' => $checkin_transact);
 }

 json_out($return);

 ?>

Now what exactly happening is .. if control is coming in while loop and email is getting send the firebug shows status as 'aborted' otherwise it is working fine ... what am I doing wrong..

Thanks in advance

Upvotes: 0

Views: 3203

Answers (2)

Avisek Chakraborty
Avisek Chakraborty

Reputation: 8309

 $.ajax({
    type: "POST",
    data: checkin_push,
    url: api_url + 'file.php?token=' + last_token + '&date=' + dated,
    ...

You are sending both GET & POST parameters. So, just want to make sure, you are not getting null for any parameter.

In file.php,

make sure to get the token and date values as $_GET

& checkin_push sent parameter-values as $_POST

or

get all the sent parameters values as $_REQUEST

Upvotes: 0

web-nomad
web-nomad

Reputation: 6003

Can you replace the following line:

error: function() {

with the following:

error: function(jqXHR, textStatus, errorThrown){

and check the value of textStatus and errorThrown to see what was the error when the request aborted.

Hope this helps.

Upvotes: 1

Related Questions