#104 XMLHttpRequest change to fetch

master
Agriya Dev5 2021-05-27 12:46:01 +05:30
parent adca890d17
commit 1abd55a698
2 changed files with 11 additions and 18 deletions

View File

@ -425,7 +425,7 @@ export default {
const header = document.createElement('h1');
browser.prepend(header);
header.textContent = allLibs;
header.setAttribute('style', `position: absolute;top: 0;left: 0;width: 100%;`);
header.setAttribute('style', `position: absolute;top: 0px;left: 0px;width: 100%;`);
const button = document.createElement('button');
// eslint-disable-next-line max-len
@ -437,10 +437,10 @@ export default {
button.addEventListener('touchend', function () {
$id("imgbrowse_holder").style.display = 'none';
});
button.setAttribute('style', `position: absolute;top: 5;right: -10;`);
button.setAttribute('style', `position: absolute;top: 5px;right: 10px;`);
const leftBlock = document.createElement('span');
leftBlock.setAttribute('style', `position: absolute;top: 5;left: 10;`);
leftBlock.setAttribute('style', `position: absolute;top: 5px;left: 10px;display: inline-flex;`);
browser.appendChild(leftBlock);
const back = document.createElement('button');

View File

@ -40,22 +40,15 @@ Array.prototype.forEach.call(atags, function (aEle) {
});
img.src = href;
} else {
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
let data = xhr.responseText;
fetch(href)
.then( (r) => r.text())
// eslint-disable-next-line promise/always-return
.then( (data) => {
post({ href, data });
return data;
} else {
return false;
}
};
xhr.open('GET', href, false);
xhr.send(null);
// Do ajax request for image's href value
/* $.get(href, function (data) {
post({ href, data });
}, 'html'); */ // 'html' is necessary to keep returned data as a string
})
// eslint-disable-next-line no-console
.catch( (error) => console.log(error));
}
return false;
});