2016-02-24 157 views
2

我想在ajax調用後停止頁面重新載入。基本上我想顯示div和填充部分視圖有一些數據。 ajax調用我的頁面後,開始刷新,如圖所示。我的代碼是如何在ajax調用jquery後阻止頁面重新載入

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 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> 

服務器端代碼的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> 

onclick事件:

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

您顯示的代碼不會刷新頁面。如果它令人耳目一新,那麼它的代碼你沒有向我們展示過。 –

+1

Ajax不會執行頁面刷新,因此您的代碼不應該導致頁面請求。 –

+0

那就是我寫的所有代碼。儘管如此,它仍然令我的網頁更加清新,我不知道爲什麼。請任何人都可以幫助我這個。預先感謝你 –

回答

1

請檢查您的控制檯使用螢火蟲。可能它是從你的腳本調用你的控制器的一些方法,它可以幫助你解決你的問題。請讓我,如果有東西。請檢查這個圖像,你的ajax調用如何在Firebug中看到的工作。

enter image description here

+0

非常感謝你的答案幫助我找出了ajax調用後發生了什麼。在ajax調用ajax調用這個make頁面後,它正在調用home索引。 Firebug是一個新的補充。非常感謝你 –

+0

非常歡迎你。 :) –

相關問題