Jquery ajaxStart赢得';t加载到Razor共享页面.Net 3.1中
我正在尝试为我的项目中的所有AJAX请求加载gif微调器,但问题是它根本无法加载 在那之前,我把它放在我需要的某些页面上,但现在我想把它放在我所有的页面上。在这一新变化之前,它运转良好 在我加载同一段javascript的其他视图中,它可以充分发挥作用 此时,我正在我的Jquery ajaxStart赢得';t加载到Razor共享页面.Net 3.1中,jquery,ajax,asp.net-core,razor,asp.net-core-3.1,Jquery,Ajax,Asp.net Core,Razor,Asp.net Core 3.1,我正在尝试为我的项目中的所有AJAX请求加载gif微调器,但问题是它根本无法加载 在那之前,我把它放在我需要的某些页面上,但现在我想把它放在我所有的页面上。在这一新变化之前,它运转良好 在我加载同一段javascript的其他视图中,它可以充分发挥作用 此时,我正在我的Views\Shared\\u NavBar\u DataUser.cshtml中的Razor页面中包含我的ajaxStart和ajaxStop方法 如果有人曾经遇到过类似的问题,如果你能给我一些关于如何解决这个问题的提示,我将不
Views\Shared\\u NavBar\u DataUser.cshtml中的Razor页面中包含我的ajaxStart
和ajaxStop
方法
如果有人曾经遇到过类似的问题,如果你能给我一些关于如何解决这个问题的提示,我将不胜感激
<nav>
<div id="divLoading" class="HideLoader">
<div>
<img asp-append-version="true" src="~/Content/Img/loading.gif" />
</div>
</div>
</nav>
<!--Cargar Iframe Tarjeta Especialista -->
<iframe frameborder="0" src='' name="genericIframe" id="genericIframe" style="display:none;">
</iframe>
<script type="text/javascript">
let divLoadAjax = window.frames.top.document.getElementById("divLoading") ?? document.getElementById("divLoading");
console.log(divLoadAjax);
$(document).ready(function () {
$(document).ajaxStart(function () {
let bodyHeight = $(divLoadAjax).closest("body").height();
$(divLoadAjax).height(bodyHeight * 2); // multiplicamos por 2 para que pueda ocupar todo el espacio de la ventana
$(divLoadAjax).show();
let mobileTablet = window.matchMedia('(max-width: 1025px)').matches;
if (!mobileTablet) {
let profileNameHeight = document.querySelectorAll(".profile-name")[0].offsetHeight;
let btnCvDoctorHeight = document.querySelectorAll(".btn-cv-doctor")[0].offsetHeight;
let specTitleHeight = document.querySelectorAll(".btn-profile")[0].offsetHeight;
let dayServiceHeight = document.querySelectorAll(".day-service")[0].offsetHeight;
let buttonReservarMasCitasHeight = document.querySelectorAll(".input-group")[0].offsetHeight;
let suma = 140 + profileNameHeight + btnCvDoctorHeight + specTitleHeight + dayServiceHeight + buttonReservarMasCitasHeight;
$("#basicModal").css("height", suma);
}
}).ajaxStop(function () {
$(divLoadAjax).hide();
});
});
</script>
让divLoadAjax=window.frames.top.document.getElementById(“divLoading”)??document.getElementById(“divLoading”);
log(divLoadAjax);
$(文档).ready(函数(){
$(文档).ajaxStart(函数(){
让bodyHeight=$(divLoadAjax).closest(“body”).height();
$(divLoadAjax).height(bodyHeight*2);//multipliamos por 2 para que pueda ocupar todo el espacio de la ventana
$(divLoadAjax.show();
让mobileTablet=window.matchMedia(“(最大宽度:1025px)”)。匹配;
如果(!mobileTablet){
让profileNameHeight=document.querySelectorAll(“.profile name”)[0].offsetHeight;
让btnCvDoctorHeight=document.queryselectoral(“.btn-cv-doctor”)[0]。偏心;
让specitleheight=document.querySelectorAll(“.btn profile”)[0].offsetHeight;
let dayServiceHeight=document.querySelectorAll(“.day service”)[0]。离视;
let ButtonReservarMasitasHeight=document.querySelectorAll(“.input group”)[0]。离视;
让suma=140+profileNameHeight+btnCvDoctorHeight+SpecitleHeight+dayServiceHeight+按钮ReserveArmaScitasHeight;
$(“基本模式”).css(“高度”,suma);
}
}).ajaxStop(功能(){
$(divLoadAjax.hide();
});
});
我尝试将您的代码放入Shared/\u Layout.cshtml,然后任何页面都会加载js。
第1页:
我发现只有在移动$(文档).ajaxStart(函数()
到$(文档)外部.ready(函数()
)时,一个Ajax请求即将发送,$(文档)。ajaxStart(函数()
将被触发
<script>
let divLoadAjax = window.frames.top.document.getElementById("divLoading") ?? document.getElementById("divLoading");
console.log(divLoadAjax);
$(document).ajaxStart(function () {
let bodyHeight = $(divLoadAjax).closest("body").height();
$(divLoadAjax).height(bodyHeight * 2); // multiplicamos por 2 para que pueda ocupar todo el espacio de la ventana
$(divLoadAjax).show();
let mobileTablet = window.matchMedia('(max-width: 1025px)').matches;
if (!mobileTablet) {
let profileNameHeight = document.querySelectorAll(".profile-name")[0].offsetHeight;
let btnCvDoctorHeight = document.querySelectorAll(".btn-cv-doctor")[0].offsetHeight;
let specTitleHeight = document.querySelectorAll(".btn-profile")[0].offsetHeight;
let dayServiceHeight = document.querySelectorAll(".day-service")[0].offsetHeight;
let buttonReservarMasCitasHeight = document.querySelectorAll(".input-group")[0].offsetHeight;
let suma = 140 + profileNameHeight + btnCvDoctorHeight + specTitleHeight + dayServiceHeight + buttonReservarMasCitasHeight;
$("#basicModal").css("height", suma);
}
}).ajaxStop(function () {
$(divLoadAjax).hide();
});
</script>
让divLoadAjax=window.frames.top.document.getElementById(“divLoading”)??document.getElementById(“divLoading”);
log(divLoadAjax);
$(文档).ajaxStart(函数(){
让bodyHeight=$(divLoadAjax).closest(“body”).height();
$(divLoadAjax).height(bodyHeight*2);//multipliamos por 2 para que pueda ocupar todo el espacio de la ventana
$(divLoadAjax.show();
让mobileTablet=window.matchMedia(“(最大宽度:1025px)”)。匹配;
如果(!mobileTablet){
让profileNameHeight=document.querySelectorAll(“.profile name”)[0].offsetHeight;
让btnCvDoctorHeight=document.queryselectoral(“.btn-cv-doctor”)[0]。偏心;
让specitleheight=document.querySelectorAll(“.btn profile”)[0].offsetHeight;
let dayServiceHeight=document.querySelectorAll(“.day service”)[0]。离视;
let ButtonReservarMasitasHeight=document.querySelectorAll(“.input group”)[0]。离视;
让suma=140+profileNameHeight+btnCvDoctorHeight+SpecitleHeight+dayServiceHeight+按钮ReserveArmaScitasHeight;
$(“基本模式”).css(“高度”,suma);
}
}).ajaxStop(功能(){
$(divLoadAjax.hide();
});
嘿,我也会试试。当我把它放在导航栏中时,它不会工作。我根本不想使用共享的/\u Layout.cshtml页面。我使用的是导航栏,它是一个共享视图。不管怎样,我在底部加载的是相同的脚本。它检测到divLoadAjax元素,但它不会进入ajaxStart。所以你知道了吗ve$(document).ajaxStart(function())在$(document).ready(function())之外,仍然无法触发ajaxStart?您需要调用一个ajax,然后将触发ajaxStart。实际上,我在几乎所有加载共享视图_NavBar\u DataUser.cshtml的视图中都这样做了。它们都至少有一个ajax请求。