我想在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);
}
您顯示的代碼不會刷新頁面。如果它令人耳目一新,那麼它的代碼你沒有向我們展示過。 –
Ajax不會執行頁面刷新,因此您的代碼不應該導致頁面請求。 –
那就是我寫的所有代碼。儘管如此,它仍然令我的網頁更加清新,我不知道爲什麼。請任何人都可以幫助我這個。預先感謝你 –