繁体   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