Почему бы просто не отправить форму и не перенаправить с сервера?
Если вы не можете просто сделать это, тогда
- Используйте jQuery, так как она у вас есть
- protectDefault для события submit, чтобы не отправлять форму
Скорее всего, вам нужно это вместо вашего xmlhttprequest. Обратите внимание на protectDefault
$(function() {
$("#yourFormId").on("submit", function(e) {
e.preventDefault(); // stop the submission
$.ajax({
type: 'post',
url: 'yourserverproces.php', // this.action will work if the form has an action
data: $(this).serialize(),
success: function(response) {
// Show a thank you message
var theLanguage = $('html').attr("lang"),
url = "/en/thanks/";
if (theLanguage == "nl-NL") {
url = "/Thanks/";
} else if (theLanguage == "fr-FR") {
url = "/fr/merci/";
}
location.href = url;
},
error: function(xhr, textStatus, error){
console.log(xhr.statusText);
console.log(textStatus);
console.log(error);
}
});
});
});