好的,我想说我想使用函数来随机页面生成随机URL。如果图像有一个类="你好"在该页面中不存在,我没有加载它。我再次使用随机URL函数,直到我找到包含带有class =" hello"的图像的页面。这是可能的吗? ?如果答案是"是"如果您能指出一些Ajax指南或任何必要的指南,我将非常感激。
答案 0 :(得分:0)
您可以根据具体要求使用Ajax。我正在使用fetch API进行演示。
以下是代码段:
function checkAndLoad(url) {
fetch(url, {
method: 'get'
}).then(function(response) {
console.log('Response Here : ', response);
// write your logic to check for Class/ID in HTML and navigate
// window.location = url;
}).catch(function(err) {
// Error :(
});
}
checkAndLoad('https://jsonblob.com/c089bff7-073a-11e7-a0ba-41ab99606d1f');