2015-04-26 154 views
0

所以基本上,我想用var allowablefile覆蓋當前的maxFileSize。但是,在控制檯中發送了正確的allowablefile值,但是當該值被覆蓋時,該值仍然是500,這是我首先聲明的值。我究竟做錯了什麼?這是整個腳本。變量傳遞未被jQuery覆蓋

<script>  
     $(document).ready(function() { 
      var allowablefile = "500"; 
      $.get("size.php", function(datas) { 
       var currfile = datas; 
       var rtplan = '<?php echo $rtplan; ?>'; 
       if (rtplan == "standard") { 
        var maxfile = "40000000"; 
        allowablefile = maxfile - currfile; 
       } 
       else if (rtplan == "pro") { 
        var maxfile = "110000000"; 
        allowablefile = maxfile - currfile; 
       } 
       else if (rtplan == "turbo") { 
        var maxfile = "60000000"; 
        allowablefile = maxfile - currfile; 
       } 
       console.log(allowablefile); 
      }); 
      var allw = allowablefile.toString(); 
      var settings = { 
       url: "../upload.php", 
       method: "POST", 
       fileName: "myfile", 
       multiple: true, 
       maxFileSize: allw, 
       uploadButtonClass:"btn btn-primary btn-block pull-right", 
       onSuccess:function(files,data,xhr) 
       { 
        $("#status").html('<span class="label label-success">File uploaded</span>').fadeIn("slow"); 
        $("#status").fadeOut(7000); 

       }, 
       onError: function(files,status,errMsg) 
       {  
        $("#status").html('<span class="label label-danger">File upload failed</span>').fadeIn("slow"); 
        $("#status").fadeOut(7000); 
       } 
      } 


      $("#mulitplefileuploader").uploadFile(settings); 
     }); 
</script> 

我試圖在一個div的name值聲明價值,但仍然沒有工作。乾杯。

回答

0

請注意,ajax調用是異步的。因此$.get()之後的行將被執行之前中的ajax成功回調行。

解決這個問題的方法是將$.get()之後的所有代碼放在$.get()成功回調中。