XMLHttpRequest() 在 Firefox 中不工作。

XMLHttpRequest() is not working in Firefox.

我不知道为什么 XMLHttpRequest() 在 Firefox 中不起作用。适用于 Chrome 和 IE。 此代码是关于更改我网站的语言。

<script type="text/javascript">
$(document).ready(function(){

$("#idioma_ingles").click(function(){
xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "?idioma=2", true);
xmlhttp.send();
  location.reload();

});

$("#idioma_espanol").click(function(){
xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "?idioma=1", true);
xmlhttp.send();
  location.reload();

  });

 });

 </script>

您在调用 send() 后立即重新加载页面(导致请求被取消)。

您可以在调用 reload() 之前等待响应,但最好不要为此使用 Ajax:没有意义。只需使用常规 link 到 ?idioma=whatever.

要么这样做,以便在请求完成后重新加载页面,要么跳过 ajax 并使用常规 link

$.get("?idioma=1", function() {
 location.reload();
});