旧行李 2016-09-26 19:45 采纳率: 25%
浏览 41

防止页面重新加载jQuery

The code is working fine for me if the page is completely loaded But the issue is if the page is in loading mode I click on the link it reloads again how I prevent it from reloading.

$(document).ready(function(){
  $('#myModal').on('show.bs.modal', function (e) {
    e.preventDefault();
    var key = $(e.relatedTarget).data('id');
    $('#loadingmessage').show();
    $.ajax({
      type : 'post',
      url : 'test.php',  
      data :  'key='+ key, 
      success : function(data) {
      $('.modal-body').html(data);
    },
    complete: function() {
      $('#loadingmessage').hide();
    }
  });
  return false;
 });
});

My Html is here

<a href='' data-toggle='modal' data-target='#myModal' data-id='1:2:3:4'>UP</a>

If page is completey loaded and i click on this the ajax call is works fine but when page is loading if i clcik the page starts reloading again how i prevent it to reload.

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
            <div class="modal-dialog" role="document">
              <div class="modal-content">
                <div class="modal-header">
                  <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                  <h4 class="modal-title" id="myModalLabel">Check Server Status</h4>
                </div>
                <div class="modal-body">
                <div id="loadingmessage">Checking...</div>
                 </div>
                <div class="modal-footer">
                  <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
              </div>
            </div>
          </div>
  • 写回答

1条回答 默认 最新

  • weixin_33674437 2016-09-26 19:47
    关注

    <a href='#' data-toggle='modal' data-target='#myModal' data-id='1:2:3:4'>UP</a>

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP