I have an issue where my JQuery AJAX call is not being executed for some users browser. Its working for most of the users. Does antivirus software/firewall or browser extension prevents the execution of AJAX call or prevents the return data from AJAX.
我有一个问题,在某些用户的浏览器上,我的JQuery AJAX调用没有被执行。它对大多数用户都有效。防病毒软件/防火墙或浏览器扩展是否会阻止执行AJAX调用或阻止从AJAX返回数据。
Does browser with disabled localStorage and/or sessionStorage prevent my JS function from executing ?
禁用了本地存储和/或会话存储的浏览器是否会阻止我的JS函数执行?
<script type="text/javascript">
sessionStorage.setItem("primaryId", 312312);
CheckData(312312);
function CheckData(primaryId) {
$.ajax({
url: '@Url.Action("CheckDataList","ControllerA")',
data: "{'PrimaryID':'" + primaryId+ "' }",
type: "POST",
contentType: "application/json;charset=utf-8",
dataType: "Json",
async: true,
success: function (result) {
if (result.length) {
var url = '@Url.Action("Index","ControllerB")';
window.location.href = url;
}
},
error: function (xhr, textStatus, errorThrown) {
}
});
}
</script>
更多回答
Disabling localStorage or sessionStorage should not directly prevent your ajax from executing. However, if there is an error while you are setting the item in session storage, it might throw and then your CheckData() call doesn't get to execute.
禁用本地存储或会话存储不应直接阻止执行您的AJAX。但是,如果在会话存储中设置项时出现错误,它可能会抛出,然后您的CheckData()调用就无法执行。
I have an issue where my JQuery AJAX call is not being executed for
some users browser. Its working for most of the users. Does antivirus
software/firewall or browser extension prevents the execution of AJAX
call or prevents the return data from AJAX.
Well, there might be numerous reasons when JavaScript or jQuery request or in particular ajax request might not be executed and its common sometimes depending on browser settings or even machine configuration, because sometimes, browser may disable script or due to security issues a machine might treat ajax request as security vulnerabilities, so we should check or verify all the prerequisites.
好吧,可能有很多原因可能不会执行JavaScript或jQuery请求,特别是AJAX请求,它的常见有时取决于浏览器设置,甚至机器配置,因为有时,浏览器可能会禁用脚本,或者由于安全问题,机器可能会将AJAX请求视为安全漏洞,所以我们应该检查或验证所有的先决条件。
First of all, double check your browser settings if there is any restriction on javascript execution. For instance, you can check following configuration in your browser:
首先,仔细检查您的浏览器设置是否有任何限制的脚本执行。例如,您可以在浏览器中检查以下配置:
Chorme browser settings:
Chorme浏览器设置:
Edge browser settings:
边缘浏览器设置:
Note: Make sure, the users where you have observed your ajax request getting failed, has no restriction on above settings.
注意:请确保您观察到您的AJAX请求失败的用户对上述设置没有限制。
Check network trace:
检查网络跟踪:
Your browser network trace will always provide you some extra information regarding your request details,so please check your network log and console. Because, depending on error code, you can decided easily whats going on. You can check properly in the browser's console and/or network tools. You should be able to retrieve the actual HTTP status code and the response given by the server (if any).
您的浏览器网络跟踪将始终为您提供有关您的请求详细信息的一些额外信息,因此请检查您的网络日志和控制台。因为,根据错误代码,您可以很容易地确定发生了什么。您可以在浏览器的控制台和/或网络工具中正确检查。您应该能够检索实际的HTTP状态代码和服务器给出的响应(如果有的话)。
Does antivirus software/firewall or browser extension prevents the
execution of AJAX call or prevents the return data from AJAX.
Of course they do. Let's say, if you are getting "403 Forbidden"
indicates that this is related to the server configuration.
他们当然会这么做。比方说,如果您收到了“403禁止”,则表示这与服务器配置有关。
Most likely, some security software or firewall on the server does not like something in
the HTTP request that is sent from the browser to the server when clicking the Save button. To find out more about this, you’d have to check your server’s error log files, maybe together with your webhost.
Then, the server configuration would have to be relaxed so that it no longer raises false positives.
很可能是服务器上的某些安全软件或防火墙不喜欢在单击保存按钮时从浏览器发送到服务器的HTTP请求中的某些内容。要了解更多这方面的信息,您必须检查服务器的错误日志文件,可能会与您的网络主机一起检查。然后,必须放宽服务器配置,使其不再引发误报。
Apart from that, For the 400 error
, it might related to the Antiforgery request. The Razor Pages is automatically protected from XSRF/CSRF. You should set the XSRF-TOKEN when you want to use the ajax to send request in razor page.
除此之外,对于400错误,它可能与防伪请求有关。Razor页面自动受到XSRF/CSRF的保护。当您想要在razor页面中使用AJAX发送请求时,需要设置xsrf-Token。
In addition to this, Same-origin policy may also cause ajax request failure.
除此之外,同源策略还可能导致AJAX请求失败。
Note: In order to checking ajax request failure, you would need to check above configuration and setting depending on the scenario.
注意:为了检查AJAX请求失败,您需要根据场景检查上面的配置和设置。
更多回答
我是一名优秀的程序员,十分优秀!