weixin_33694172 2020-04-23 03:57 采纳率: 0%
浏览 28

Ajax加载未出现

i have function ajax post that triggred after upload_btn click on my modal

// the modal
    <div class="modal-footer">      
        <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
        <button type="button" id="upload_btn" class="btn btn-primary btn-sm"><i class="fa fa-upload" data-toggle="tooltip" data-placement="top" title="Upload template"></i> Upload</button>
      </div>

$("#upload_btn").on('click', function(){
    var mydata = new FormData(document.getElementById("form_upload"));
    $.ajax({
      type : "POST",
      data: mydata,
      contentType: false,
      dataType : 'json',
      url : "<?php echo base_url();?>/C_MRCR_A/do_upload",
      cache: false,
      processData: false,
      beforeSend:function(){
        $("#loader").show();
      },
      success:function(response){        
        if(response.upload_success){
          $('#response-alert').html('<div class="alert alert-success" role="alert"> '+response.upload_success+' </div>');
        } else if(response.upload_success_partial){
          $('#response-alert').html('<div class="alert alert-warning" role="alert"> '+response.upload_success_partial+' </div>');
        } else if(response.upload_error){
          $('#response-alert').html('<div class="alert alert-danger" role="alert"> '+response.upload_error+' </div>');
        } else if(response.detail_error){
          $('#response-alert').html('<div class="alert alert-danger" role="alert"> '+response.detail_error+' </div>');
        } else {
          $('#response-alert').html('<div class="alert alert-danger" role="alert"> '+response.db_error+' </div>');
        }
        $("#form_result").removeAttr("style", true);
        $("#loader").hide();
      }
...

//i place this outside my modal
<!-- loader -->
<div id='loader' style='display: none;'>
  <img src='<?php echo base_url(); ?>assets/loading/ajax-loader.gif' width='32px' height='32px'>
</div>
<!-- loader -->

it supposed the loading appear after i click the upload_btn and dissmiss after the success:function. but it is not. what i did wrong?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥15 stable diffusion
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误