【问题标题】:Ambiguous JQuery redirection from ajax post callback来自 ajax 后回调的模棱两可的 JQuery 重定向
【发布时间】:2016-05-02 09:41:05
【问题描述】:

Firefox 和 Chrome 之间的模棱两可的行为。 这是我的 ajax 调用:

$.ajax({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    dataType: "text",
    url: "client",
    data: "{\"operationType\": \"Update\", \"body\": \"" + JSON.stringify(formAsJson).replace(/\"/g, "'") + "\"}",
    async: false,
  })
  .done(function() {
    window.location.replace("success.html");
    alert("Success");
  })
  .fail(function() {
    alert("failure");
  });

问题 1:如果存在 alert("Success"),则重定向在 Firefox 中可以正常工作,而在 Chrome 中重定向不会发生,但会显示警报。对此行为的解释。

问题2:如何重定向到独立于浏览器的页面?

如果我在 done 回调中注释 alert("Success"),重定向在 mozilla 中不起作用但在使用 firebug 调试时,它起作用。

在 chrome 上,无论有没有调试器,它都无法正常工作。

附:使用调试器检查控制是否转到两个浏览器中的重定向语句。

【问题讨论】:

  • 尝试在success 之前添加一个斜杠。 window.location.replace("/success.html");
  • 重定向前为什么不alert
  • @Bruno 添加 / 没有帮助。
  • @Alexis 与 .replace() 中提到的行为相同。
  • @GuruprasadRao 重定向在 mozilla 中只有在重定向后放置警报时才会成功。

标签: jquery ajax redirect


【解决方案1】:

我发现这可能对您有所帮助:window-location-href-not-working, 你有没有试过在window.location.replace("success.html");之后添加return false;

【讨论】:

  • 不,它没有帮助。在 Mozilla 中,如果跟随警报,重定向会实时工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-06-30
  • 1970-01-01
  • 2023-04-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多