Hello, I am currently working on a script that involves AJAX functionality:
function ajax(){
if (navigator.standalone) return;
for (var i= document.links.length; i-->0;) {
document.links[i].onclick= function() {
var req= new XMLHttpRequest();
req.onreadystatechange= function() {
if (this.readyState!==4) return;
document.body.innerHTML= this.responseText;
ajax();
};
req.open('GET', this.href, true);
req.send();
return false;
};}
}
window.onload= function() {
window.scrollTo(0, 0.9);
ajax();
};
Now, I have a requirement to add a condition where if a link has a class named "noeffect", the AJAX execution should be skipped, and another page should load instead. I attempted to implement this feature but encountered challenges due to my limited understanding of JavaScript:
function ajax(){
if (navigator.standalone) return;
for (var i= document.links.length; i-->0;) {
if (document.links[i].getAttribute("class") == "noeffect") return;
document.links[i].onclick= function() {
var req= new XMLHttpRequest();
req.onreadystatechange= function() {
if (this.readyState!==4) return;
document.body.innerHTML= this.responseText;
ajax();
};
req.open('GET', this.href, true);
req.send();
return false;
};}
}
window.onload= function() {
window.scrollTo(0, 0.9);
ajax();
};
I understand that the code may not be correctly checking each link individually, and I'm seeking guidance on how to modify it appropriately.