$ .ajax使用async:false cant使用timeout:5000,如何同时使用?

时间:2018-01-31 09:08:00

标签: javascript jquery ajax

以下是一个例子:

var dailyValue = sheet.getRange('F5')
var lastA = sheet.getRange(sheet.getLastRow(),2,1)
var formula = "=" + lastA + "*" + dailyValue

emptyB.setFormula([formula])

1 个答案:

答案 0 :(得分:-1)

您可以使用setTimeout。试试这个:

var xhr = '';
xhr = $.ajax({
   type: 'POST',
   url: c.cls.server,
   data: {
     mode: 'Perspective',
     id: c.uid,
     points: points,
     width: c.cls.canvasMaxWidth,
     caseid: caseid,
     imgtype: imgtype
   },
   async: false,   
   contentType: "application/x-www-form-urlencoded",
   beforeSend: function(e){

      setTimeout(function(){ 
        if(xhr && xhr.readyState != 4) xhr.abort();
      },5000);

   },success: function(e) {
     result = e;
   },
   error: function(r, s, e) {
     c.onError(status + e);
   }
});