Я пытаюсь изменить URL-адрес (без обновления страницы) после изменения DOM с помощью Ajax.
$("nav li").click(function(e) {
e.preventDefault();
var url;
var targetLocation = this.parentNode.attributes.href.value;
switch (targetLocation) {
case "index.html": url = "http://localhost:8080/home"; break;
case "app.html": url = "http://localhost:8080/api"; break;
case "contact.html": url = "http://localhost:8080/contact"; break;
}
$.ajax({
type: "GET",
dataType: "text",
url: url,
context: document.body,
success: function(data) {
$("div").text(data);
history.pushState("", "", targetLocation);
}
})
})
Но я получаю сообщение об ошибке:
Uncaught DOMException: failed to execute "pushState" on "History": A history state object with URL "file:///C:/test/app.html" cannot be created in a document with origin "null" and URL "file:///C:/test/index.html".