繁体   English   中英

Ajax 在 Chrome 或 IE 中不起作用,但在 FireFox 中起作用

[英]Ajax not working in Chrome or IE but does in FireFox

我在我的一个网站上遇到了一些意想不到的问题,我以为我的 Ajax 可以正常工作,但后来我注意到它只能在 Firefox 中工作。

在 Chrome 控制台中调试时,我看到:

invoke.js:1 Console was cleared
main.js:42 in Startnull
prompt.js:1 Uncaught SyntaxError: Identifier 'originalPrompt' has already been declared
/favicon.ico:1 Failed to load resource: the server responded with a status of 404 (Not Found)
Unchecked runtime.lastError: The message port closed before a response was received.
Unchecked runtime.lastError: The message port closed before a response was received.
Unchecked runtime.lastError: The message port closed before a response was received.
Unchecked runtime.lastError: The message port closed before a response was received.
Unchecked runtime.lastError: The message port closed before a response was received.
Unchecked runtime.lastError: The message port closed before a response was received.
main.js:42 in Startnull
prompt.js:1 Uncaught SyntaxError: Identifier 'originalPrompt' has already been declared
mc_ns_26.06.2018_728x90_8_en.jpg:1 Failed to load resource: net::ERR_BLOCKED_BY_CLIENT
main.js:42 in Startnull
prompt.js:1 Uncaught SyntaxError: Identifier 'originalPrompt' has already been declared
1588423983.jpg:1 Failed to load resource: net::ERR_BLOCKED_BY_CLIENT
DevTools failed to load source map: Could not load content for chrome-extension://ljdobmomdgdljniojadhoplhkpialdid/common/browser-polyfill.js.map: HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME
DevTools failed to load source map: Could not load content for chrome-extension://mooikfkahbdckldjjndioackbalphokd/assets/atoms.js.map: HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME
DevTools failed to load source map: Could not load content for chrome-extension://mooikfkahbdckldjjndioackbalphokd/assets/polyfills.js.map: HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME
DevTools failed to load source map: Could not load content for chrome-extension://mooikfkahbdckldjjndioackbalphokd/assets/escape.js.map: HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME
DevTools failed to load source map: Could not load content for chrome-extension://mooikfkahbdckldjjndioackbalphokd/assets/playback.js.map: HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME
DevTools failed to load source map: Could not load content for chrome-extension://mooikfkahbdckldjjndioackbalphokd/assets/record.js.map: HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME
jquery-3.5.1.js:10099 POST https://www.quiz-griz.com/30-how-well-do-you-know-the-vampire-diaries-characters/ajax-answer.php 404 (Not Found)
send @ jquery-3.5.1.js:10099
ajax @ jquery-3.5.1.js:9682
AjaxRequest @ global.js:11
AnswerQuestion @ global.js:67
onclick @ (index):86

问题在这里:

jquery-3.5.1.js:10099 POST https://www.quiz-griz.com/30-how-well-do-you-know-the-vampire-diaries-characters/ajax-answer.php 404 (Not Found)

它试图在重写 .htaccess url 后加载我的 ajax 文件,位置真的在这里/ajax/ajax-answer.php在我的服务器和我的 javascript 代码中。

这是我引用文件位置的代码:

function AnswerQuestion(el) {
  const $el = $(el);
  //alert($el.data('question-id'));
  if ($el.hasClass('disabled'))
    return;
  $el.addClass('disabled');
  const url = '/ajax/ajax-answer.php';
  let pars = {
    answer: $('input[name=questions]:checked', '#question-form').val(),
    takenQuizId: $el.data('taken-quiz-id'),
    quizId: $el.data('quiz-id'),
    questionId: $el.data('question-id'),
  };
  AjaxRequest(url, pars, function(response) {
    // success goes here
    $el.removeClass('disabled');
    console.info("SUCCESS->", response);
    location.reload();
  },
  function (response) {
    // fail goes here
    $el.removeClass('disabled');
    console.info("FAIL->", response);
  });
}


$(document).ready(function() {
  $("#question-form input").on("change", function(){
    $(".btn").removeClass('disabled');
  });
});

这在 Firefox 中运行良好,但在 Chrome 和 Internet Explorer 中它不想工作。

我想不出要尝试什么,有什么我可以调整来解决这个问题的吗?

信不信由你这是两个浏览器的缓存问题! 一旦清除它开始工作。

我有过这个问题的经验,可能会有所帮助。 在我的项目中,我被授予管理员用户对 ajax 请求页面的访问权限,但我正在使用普通用户测试该功能,但无法访问该页面。 所以ajax没有按预期响应。 我很奇怪地说它只能在其他浏览器中工作,因为在其他浏览器中我以管理员用户身份登录,而在 firefox 中仅以非特权用户身份登录。 那很搞笑,不是吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM