Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/443.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在手动结束javascript函数之前,我应该让它运行多长时间?_Javascript_Jquery_Ajax - Fatal编程技术网

在手动结束javascript函数之前,我应该让它运行多长时间?

在手动结束javascript函数之前,我应该让它运行多长时间?,javascript,jquery,ajax,Javascript,Jquery,Ajax,我有一个javascript函数,其中包含大约4个ajax请求。通常运行时间不到一秒钟。但是,我现在正在进行错误处理,我想知道。在手动取消javascript函数并允许用户重试之前,我应该允许javascript函数尝试保持工作多长时间(以秒为单位) 下面是所讨论的函数的外观。(并非所有内容都在那里,但它可能有(1000*5000*3)+(70)+(1000)+(6)+(2500)个字节正在发送) 函数保存更改(保存){ //bypassDeckSave=未定义-不绕过 showSavedNot

我有一个javascript函数,其中包含大约4个ajax请求。通常运行时间不到一秒钟。但是,我现在正在进行错误处理,我想知道。在手动取消javascript函数并允许用户重试之前,我应该允许javascript函数尝试保持工作多长时间(以秒为单位)

下面是所讨论的函数的外观。(并非所有内容都在那里,但它可能有(1000*5000*3)+(70)+(1000)+(6)+(2500)个字节正在发送)

函数保存更改(保存){
//bypassDeckSave=未定义-不绕过
showSavedNotification_check=1;
if(userid!=0){
//数据库中的值
var subjectID=$('.lib_folder_id').val(),
folderID=$('.lib_subject_id').val();
如果(subjectID==0 | | folderID==0){//如果数据库值为null,则询问一些
log(“未保存db数据组位置,已请求”);
//要设置为的值
var setFolderID=$('.libDeckLocationModifierDiv.folders li.on').val(),
setSubject=$('.libDeckLocationModifierDiv.subjects li.on').val();
if(isNaN(setFolderID)| isNaN(setSubjectID)||
setFolderID==0 | | setSubjectID==0)
{
openDeckLocationDiv();
showSavedNotification_check=0;
返回;
}
}
}
var deck_id=$('.deck_id').val();
if(deck_id==0){
//创建一个新的组
createDeckThenSave();
返回;
}
if(userid!=0){
//数据库中的值
var subjectID=$('.lib_folder_id').val(),
folderID=$('.lib_subject_id').val();
如果(subjectID==0 | | folderID==0){//如果数据库值为null,则询问一些
//要设置为的值
saveDeckLocation();
}
}
//删除空行
$('.editMain li')。每个(函数(){
var one=$(this.find('.text1').val(),
two=$(this.find('.text2').val();
如果(一==“”&二==“”){
//删除此行并从updateSaveArray+add to delete数组中删除值
var currentval=$(this.val();
var rowid=“.row_u3;”+currentval;
updateSaveArray=jQuery.grep(updateSaveArray,函数(值){
返回值!=currentval;
});
$(rowid.remove();
updateDeleteArray[updateDeleteArray.length]=currentval;
}
});
如果(保存==未定义){
//将数据组信息保存到数据库
var deckname=$('.editDeckNameInput').val(),
cardCount=$('.editMain li.mainLi:visible')。长度,
deckTermLanguage=$('.selector.one select').val(),
deckDefinitionLanguage=$('.selector.two select').val(),
deckThirdBoxLanguage=$('.selector.three select').val(),
deckDescription=$('.editMoreDeckOptionsDiv textarea').val();
if($('.editMoreDeckOptions.onlyme').hasClass(“on”)){
var-viewPreferences=1;
}否则{
var-viewPreferences=0;
}
if($('.editUseThirdboxDiv').hasClass('on')){var thirdbox=1;
}else{var thirdbox=2;}
//log(“调用deckInfoSave”);
$.ajax({
类型:“POST”,
url:“/edit/deckInfoSave.php”,
数据:{pDeckid:deck_id,pDeckname:deckname,pCardCount:cardCount,
pDeckTermLanguage:deckTermLanguage,pDeckDefinitionLanguage:deckDefinitionLanguage,
pDeckThirdBox语言:DeckThirdBox语言,pThirdbox:thirdbox,
pDeckDescription:deckDescription,pViewPreferences:viewPreferences
}
})
.完成(功能(数据){
//控制台日志(数据);
//平均值=1;
saveDeckInfoHasFinished=1;
});
}否则{
saveDeckInfoHasFinished=1;
}
//准备已编辑的卡片阵列
//获取holdSaveCardArray中所需的所有值和存储
var holdSaveCardArray=[];
对于(i=0;ifunction saveChanges(bypassDeckSave){ 
  // bypassDeckSave = undefined - does not bypass
  showSavedNotification_check = 1;

  if(userid != 0){
    //values in database
    var subjectID = $('.lib_folder_id').val(),
        folderID = $('.lib_subject_id').val();

    if(subjectID == 0 || folderID == 0){//if database values null, ask for some
      console.log("db deck location not saved, asked for it");

      //values to set to 
      var setFolderID = $('.libDeckLocationModifierDiv .folders li.on').val(),
          setSubjectID = $('.libDeckLocationModifierDiv .subjects li.on').val();

      if(isNaN(setFolderID) || isNaN(setSubjectID) ||
          setFolderID == 0 || setSubjectID == 0)
      {
        openDeckLocationDiv();
        showSavedNotification_check = 0;
        return;
      }
    }
  }


  var deck_id = $('.deck_id').val();
  if(deck_id == 0){
    // create a new deck
    createDeckThenSave();
    return;
  }



  if(userid != 0){
    //values in database
    var subjectID = $('.lib_folder_id').val(),
        folderID = $('.lib_subject_id').val();

    if(subjectID == 0 || folderID == 0){//if database values null, ask for some
      //values to set to 
      saveDeckLocation();  
    }
  }



  // removes empty rows
  $('.editMain li').each(function(){
    var one   = $(this).find('.text1').val(),
        two   = $(this).find('.text2').val();
    if(one == "" && two == ""){
      //remove this row and remove value from updateSaveArray + add to delete array
      var currentval = $(this).val();
      var rowid = ".row_"+currentval;

      updateSaveArray = jQuery.grep(updateSaveArray, function(value) {
        return value != currentval;
      });
      $(rowid).remove();
      updateDeleteArray[updateDeleteArray.length] = currentval;
    }
  });



  if(bypassDeckSave == undefined){
    // save deck info to db
    var deckname  = $('.editDeckNameInput').val(),
        cardCount = $('.editMain li.mainLi:visible').length,

        deckTermLanguage = $('.selector.one select').val(),
        deckDefinitionLanguage = $('.selector.two select').val(),
        deckThirdBoxLanguage = $('.selector.three select').val(),

        deckDescription = $('.editMoreDeckOptionsDiv textarea').val();

    if($('.editMoreDeckOptionsSelector .onlyme').hasClass("on")){
      var viewPreferences = 1;
    }else{  
      var viewPreferences = 0; 
    }

    if($('.editUseThirdboxDiv').hasClass('on')){ var thirdbox = 1;
    }else{ var thirdbox = 2; }

    // console.log("deckInfoSave called");
    $.ajax({
      type: "POST",
      url: "/edit/deckInfoSave.php",
      data: { pDeckid: deck_id, pDeckname: deckname, pCardCount: cardCount, 
        pDeckTermLanguage: deckTermLanguage, pDeckDefinitionLanguage: deckDefinitionLanguage,
        pDeckThirdBoxLanguage: deckThirdBoxLanguage, pThirdbox: thirdbox,
        pDeckDescription: deckDescription, pViewPreferences: viewPreferences
      }
    })
    .done(function(data){
      // console.log(data);
      // decksaved = 1;
      saveDeckInfoHasFinished = 1;
    });
  }else{
    saveDeckInfoHasFinished = 1;
  }





  // prepares edited card array
  // gets all needed values and stores in holdSaveCardArray
  var holdSaveCardArray = [];
  for (i = 0; i < updateSaveArray.length; ++i) {
    var currentCard_id    = updateSaveArray[i],
        rowidClass        = ".row_"+currentCard_id,
        text1val          = $(rowidClass+" .text1").val(),
        text2val          = $(rowidClass+" .text2").val(),
        text3val          = $(rowidClass+" .text3").val();
        cardOrder         = $(".editMain li.mainLi:visible").index($(rowidClass)) + 1;

    holdSaveCardArray[holdSaveCardArray.length] = {
      "card_id":        currentCard_id,
      "text1val":       text1val,
      "text2val":       text2val,
      "text3val":       text3val,
      "cardOrder":      cardOrder
    };

  }
  // console.log(print_r(holdSaveCardArray));

  // delete cards start
  // deletes any card with an id in updateDeleteArray
  $.ajax({
    type: "POST",
    url: "/edit/deleteCards.php",
    data: { pDeck_id: deck_id, pDeleteArray: updateDeleteArray }
  })
  .done(function( msg ) {
    // $('.temp').append(msg);
    updateDeleteArray = [];
    deleteCardsHasFinished = 1;
  }); 



  // save cards to database
  // loops through each card that had changes made to it

  $.ajax({
    type: "POST",
    url: "/edit/saveCardsArray.php",
    dataType: "JSON",
    data: { pDeck_id: deck_id, pCardArray: holdSaveCardArray}
  }).done(function(data){
    for (var i = 0; i < data.length; i++) { 
      var temp_id           = data[i]["temp_id"], // new id
          card_key          = data[i]["card_key"], // old id
          currentClassName  = 'row_'+temp_id,
          currentClass      = '.row_'+temp_id,
          nextClassName     = 'row_'+card_key;
      $(currentClass).val(card_key);
      $(currentClass).removeClass(currentClassName).addClass(nextClassName);
    }
    saveCardsHasFinished = 1;
  });
  updateSaveArray = [];




  // update order start  // uses li value
  updateOrderArray = [];
  $('.editMain').find(".mainLi").each(function(){
    var temp = $(this).val();
    updateOrderArray[updateOrderArray.length] = temp;
  });
  $.ajax({
    type: "POST",
    url: "/edit/orderCards.php",
    data: { pUpdateOrderArray: updateOrderArray }
  })
  .done(function( msg ) {
    updateOrder = 0;
    updateOrdersHasFinished = 1;
  }); 


  closeLibDLM(); console.log("closeLibDLM1");
  changeSaveStudyButton(1);


} //saveChanges function end