簡體   English   中英

為什么ajax請求被中止……?

[英]Why ajax request is getting aborted …?

我正在向服務器發送ajax請求

$.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);
    }
});

這是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);

 ?>

現在確切發生的是..如果控件進入while循環並且電子郵件正在發送,則螢火蟲將狀態顯示為“異常終止”,否則工作正常……我在做什么錯..

提前致謝

您可以替換以下行:

error: function() {

具有以下內容:

error: function(jqXHR, textStatus, errorThrown){

並檢查textStatuserrorThrown的值以查看中止請求時發生了什么錯誤。

希望這可以幫助。

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

您正在發送GET和POST參數。 因此,僅需確保您沒有為任何參數獲取null

在file.php中,

確保將tokendate值獲取為$_GET

checkin_push將參數值發送為$_POST

要么

獲取所有發送的參數值,為$_REQUEST

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM