为什么JavaScript表单可以在Chrome中使用而不能在Firefox中使用
我需要在Firefox中执行以下函数,但在chrome中运行良好。问题是当我“用Firebug检查元素”时,它工作正常。方法“EditEncounterBillStatus”也正确命中。但是,当我不使用'Inspect Element With Firebug'时,EditEncounterBillStatus方法不会命中。。我做了很多努力来解决这个问题。但我还是不能有人帮我找到解决方案,谢谢提前为什么JavaScript表单可以在Chrome中使用而不能在Firefox中使用,javascript,jquery,google-chrome,firefox,Javascript,Jquery,Google Chrome,Firefox,我需要在Firefox中执行以下函数,但在chrome中运行良好。问题是当我“用Firebug检查元素”时,它工作正常。方法“EditEncounterBillStatus”也正确命中。但是,当我不使用'Inspect Element With Firebug'时,EditEncounterBillStatus方法不会命中。。我做了很多努力来解决这个问题。但我还是不能有人帮我找到解决方案,谢谢提前 else if (element.trim() == "Approved") {
else if (element.trim() == "Approved") {
var TestPin = prompt("Please Enter your PIN");
if (TestPin != null) {
if (isNaN(TestPin)) {
alert("Please Enter a Valid Pin");
return;
}
else if (TestPin == pin) {
var postVisitData = { VisitId: vid};
$.post("/Emr/WaitingRoom/EditEncounterBillStatus", { VisitId: vid }, function (data) {
});
window.location = "/Emr/Patients/Show?PID=" + pid;
}
else {
alert("Your Entered PIN Is Incorrect");
}
}
else {
return;
}
}
我建议你这样做
else if (TestPin == pin) {
$.post("/Emr/WaitingRoom/EditEncounterBillStatus", { VisitId: vid }, function (data) {
window.location = "/Emr/Patients/Show?PID=" + pid;
});
return; // in case of side effects in unseen code
}
i、 e.在更改window.location之前,请等待$.post完成
由于代码的其余部分是看不见的,因此以这种方式执行可能会有副作用-因此返回它所在的位置-但即使如此,不知道完整的调用堆栈仍可能有副作用-您已收到警告,您应该在
post
调用成功后更改位置,因此,将其放在回调函数体中:
$.post("/Emr/WaitingRoom/EditEncounterBillStatus", { VisitId: vid },
function (data) {
window.location = "/Emr/Patients/Show?PID=" + pid;
});
这样,您可以确保只有在执行
post
操作时才更改位置。否则,您可能会在post
发生之前更改位置。在调试模式下,当然,当您逐步完成代码时,有足够的时间让post
及时完成,因此,您的原始代码可以正常工作。执行$后,通过更改窗口,您可以有效地取消$.post
。post
-在chrome中正常工作的事实可能是偶然的。我如何根据答案更正它:p