如何在ajax调用jquery之后阻止页面重新加载

时间:2016-02-24 11:51:52

标签: c# jquery ajax asp.net-mvc

我想在ajax调用后停止页面重新加载。基本上我想显示div并填充具有一些数据的局部视图。在ajax调用之后,我的页面开始刷新,如图所示。我的代码是

    function GetAllSlot(doctorid, schid, dayid) {

       $("#doctorsScheduler").html('');
       $.ajax({
           url: '/Appointment/GetAllSlotsForDoc',
           type: 'GET',
           data: { doctorId: doctorid, schid: schid, dayID: dayid },
           async : true,
           success: function (innerData) {
               $("#doctorsScheduler").slideToggle("slow", function () {
                   $("#doctorsScheduler").html(innerData);
               });
           }
       });
   }

我的div

<div class="col-lg-12 col-sm-12 col-md-12">
       <div class="row">
           <div class="card-box" style="display: none;" id="doctorsScheduler">
           </div>
       </div>
   </div>

在Div上点击事件

<div class="col-sm-2" onclick="GetAllSlot(@item.ID,@items.ID,@items.DayID)">
               <a href="#">
                   <div class="card-box  bg-success">
                       <div class="media">
                           <div class="media-left">
                               <img class="media-object" src="~/Content/Hosiptal-icon/DoctorsApp.png" alt="">
                           </div>
                           <div class="media-right">
                               <h4 class="media-heading" style="text-align: left; width: 500%; color: black">@item.DoctorName</h4>
                           </div>
                       </div>
                   </div>
               </a>
           </div>

服务器端代码:

public ActionResult GetAllSlotsForDoc(long doctorId,long schid, long dayID)
   {

       var roomno = (from p in db.SchedulerSettings where p.FKDoctorID == doctorId && p.DayID == dayID select p.RoonNo).
             Single();
       ViewBag.DayOfWeek = (DayOfWeek)dayID;
       ViewBag.RoomNo = roomno;
       var getslotsfordoct = new GetSlotsForDoctor();
       var appointmentlist = getslotsfordoct.GetSlotsforDoctor(doctorId,schid,dayID);
       return PartialView("~/Views/PartialViews/AppointmentDeskDashBoard/_GetAppointmentSlotsPartailView.cshtml", appointmentlist);
   }

enter image description here

1 个答案:

答案 0 :(得分:1)

请使用firebug查看您的控制台。可能它会从你的脚本中调用你的一些控制器方法,它可以帮助你解决你的问题。如果有什么东西,请让我。请查看这张图片,了解你的ajax调用如何在firebug中看到。

enter image description here