发布事件结束后,我需要将页面重定向到某个URL
我有一项任务,我需要在单击按钮时调用AMP事件。但是我收到的错误是“未捕获的TypeError:无法分配为只读对象'[object WorkerLocation]'的属性'href' 在XMLHttpRequest.xhttp.onreadystatechange(fbd7c59c-7201-4dac-af7d-b737f74a7653:67)“
function loadDoc(urladd) {
console.log(urladd);
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
const response = this.responseText;
var obj = JSON.parse(response);
console.log(obj);
if (obj.updatetopcartsectionhtml) {
document.getElementById("topcartlink").innerHTML = obj.updatetopcartsectionhtml;
}
if (obj.success) {
console.log("aaaaaaaaa" + obj.success);
}
if (obj.redirect) {
console.log("start");
//window.location = "HTTP://WWW.GOOGLE.COM";
//window.URL.revokeObjectURL("HTTP://WWW.GOOGLE.COM");
location.href = 'http://www.example.com'; //or
location.assign("http://www.mozilla.org"); // or
location = "http://www.mozilla.org";
console.log("end");
//window.location = "http://localhost:15536/build-your-own-computer";
//const canon = "http://localhost:15536/build-your-own-computer";
//document.location = canon.href;
}
}
};
xhttp.open("POST", "http://localhost:15536/addproducttocart/catalog/1/1/1", true);
xhttp.send();
}