user1598550
user1598550

Reputation: 105

XMLHttpRequest() is not working in Firefox.

I don't know why XMLHttpRequest() is not working in Firefox. Works in Chrome and IE. This code is about change the language of my website.

<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>

Upvotes: 1

Views: 263

Answers (2)

BobbyTables
BobbyTables

Reputation: 4705

Either do it like this so the page get reloaded after the request is done, or just skip the ajax and use a regular link

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

Upvotes: 1

Quentin
Quentin

Reputation: 944438

You're reloading the page (causing the request to be canceled) immediately after you call send().

You could wait for the response before calling reload() but it would b be better to simply not use Ajax for this: there's no point. Just use a regular link to ?idioma=whatever.

Upvotes: 0

Related Questions