简体   繁体   English

为什么ajax请求被中止……?

[英]Why ajax request is getting aborted …?

I am sending ajax request to server 我正在向服务器发送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);
    }
});

Here is relevant code of file.php 这是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.. 现在确切发生的是..如果控件进入while循环并且电子邮件正在发送,则萤火虫将状态显示为“异常终止”,否则工作正常……我在做什么错..

Thanks in advance 提前致谢

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. 并检查textStatuserrorThrown的值以查看中止请求时发生了什么错误。

Hope this helps. 希望这可以帮助。

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

You are sending both GET & POST parameters. 您正在发送GET和POST参数。 So, just want to make sure, you are not getting null for any parameter. 因此,仅需确保您没有为任何参数获取null

In file.php, 在file.php中,

make sure to get the token and date values as $_GET 确保将tokendate值获取为$_GET

& checkin_push sent parameter-values as $_POST checkin_push将参数值发送为$_POST

or 要么

get all the sent parameters values as $_REQUEST 获取所有发送的参数值,为$_REQUEST

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM