简体   繁体   中英

Change HTML location jQuery ajax beforesend in ios

I have code like below. Because if user's answer is disagree , I have to send mails to some people. And it takes a lot of time on sending mails ,that user can't go to the thank you page(QNR05.html) quickly because of the run_waitMe(waitMe.min.js). So I change the ajax success to beforesend for this problem .

But!!! This works good on PC and android phone . But it won't send anything to updateFollowup.do on ios device , just simply change page to thank you page(QNR05.html). I have one solution is change sending mail to batch in backgroud process . But it will change code a lot . So I wonder if any solution to change page before callback in ios device and will send data indeed .Any solution will be appreciate. Thanks a lot any way.

ps all I test is in chrome . hope the solution is work good in chome . thanks!

function postData(followup) {
  run_waitMe($('#bodyLock'),'img', '','60','vertical','30px');
  if ("N" == haveQ2) {
    var cbxVehicle1 = new Array();
    $('input:checkbox:checked[name="answer1Val"]').each(function(i) { cbxVehicle1[i] = this.value; });

    $.ajax({
      type: "POST",
      url: "QNR04/updateFollowup.do",
      data : {
        "masterId" : $('#masterId').val(),
        "answer1" : $("#qa1").val(),
        "question1" : $('#service1').val(),
        "answerDesc1" : cbxVehicle1.toString(),
        "followUp" : followup,
        "contactPhone" : $("#contactPhone").val(),
        "serviceName":"客戶回報問卷-送出"
      },
      beforeSend: function(msg) {
        location.href = "QNR05.html";
      }
    });

  } else {
    var cbxVehicle1 = new Array();
    $('input:checkbox:checked[name="answer2Val"]').each(function(i) { cbxVehicle1[i] = this.value; });

    var cbxVehicle2 = new Array();
    $('input:checkbox:checked[name="answer3Val"]').each(function(i) { cbxVehicle2[i] = this.value; });

    $.ajax({
      type: "POST",
      url: "QNR04/updateFollowup.do",
      data : {
        "masterId" : $('#masterId').val(),
        "answer1" : $("#qa1").val(),
        "question1" : $('#service2').val(),
        "answerDesc1" : cbxVehicle1.toString(),
        "answer2" : $("#qa2").val(),
        "question2" : $('#service3').val(),
        "answerDesc2" : cbxVehicle2.toString(),
        "followUp" : followup,
        "contactPhone" : $("#contactPhone").val(),
        "serviceName":"客戶回報問卷-送出"
      },
      beforeSend: function(msg) {
        location.href = "QNR05.html";
      }
    });
  }
}

Since you don't want to "wait" for the success callback...

Then in beforeSend: , use a timeout, so the Ajax should have time to send... At least.

beforeSend: function(){
  setTimeout(function(){
    location.href = "QNR05.html";
  },100);
}

100 ms should be way enough... And the user won't notice.
Try with a little longer delay if it fails.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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