store pics from api in db

This commit is contained in:
lukas-heiligenbrunner
2020-04-04 19:44:31 +02:00
parent 9a8d2dea0b
commit 177e267e18
4 changed files with 53 additions and 26 deletions

View File

@ -14,6 +14,21 @@ class Req {
xhttp.send(data);
}
static postData(url, data, callback) {
const xhttp = new XMLHttpRequest();
xhttp.open("POST",url,true);
xhttp.onload = function(){
if (this.readyState == 4 && this.status == 200) {
callback(xhttp.responseText);
}
}
xhttp.onerror = function () {
console.log("error")
};
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send(data);
}
static get(url, callback) {
const xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function(){

View File

@ -1,22 +1,22 @@
Req.ready(() => {
Req.post("php/index.php", "action=getMovies&test=2", function (dta) {
console.log(dta);
for (const ii in dta.data) {
document.getElementsByClassName("mediawrapper").item(0).insertAdjacentHTML('beforeend', `
<div class="mediatile">${dta.data[ii].url}</div>`); // <video controls src="${dta.data[ii].url}"></video>
}
// Req.post("php/index.php", "action=getMovies&test=2", function (dta) {
// console.log(dta);
// for (const ii in dta.data) {
// document.getElementsByClassName("mediawrapper").item(0).insertAdjacentHTML('beforeend', `
// <div class="mediatile">${dta.data[ii].url}</div>`); // <video controls src="${dta.data[ii].url}"></video>
// }
// });
//
// Req.post("php/index.php", "action=storePic", function (dta) {
// console.log(dta);
// });
console.log("startup")
Req.postData("php/index.php", "action=readPic", function (dta) {
document.getElementById("tempici").src = dta;
});
Req.post("php/index.php", "action=storePic", function (dta) {
console.log(dta);
});
Req.post("php/index.php", "action=readPic", function (dta) {
console.log(dta);
document.getElementById("tempici").src = dta.data;
});
Req.post("php/index.php", "action=getDbSize", function (dta) {
console.log(dta);
});
// Req.post("php/index.php", "action=getDbSize", function (dta) {
// console.log(dta);
// });
});