blazerapp/cms/static/utils.js

59 lines
1.8 KiB
JavaScript
Raw Normal View History

2021-09-11 17:49:27 -04:00
function forwardForImage(id, postloc) {
console.log("askldjf");
let form_elem = document.getElementById(id).children;
let data = [];
2021-09-12 17:30:56 -04:00
var base64=""
2021-09-11 17:49:27 -04:00
for (i = 0; i < form_elem.length; i++) {
console.log(form_elem[i]);
if (form_elem[i].type == "text") {
data.push(form_elem[i].name + "=" + encodeURIComponent(form_elem[i].value));
}
if (form_elem[i].type == "select-one") {
data.push(form_elem[i].name + "=" + encodeURIComponent(form_elem[i].value));
}
if (form_elem[i].type == "file") {
2021-09-12 17:30:56 -04:00
var file = document.querySelector('input[type=file]')['files'][0]
var reader = new FileReader();
reader.readAsDataURL(file)
reader.onload=function() {
base64 = reader.result
};
reader.onerror = function (error) {
console.log('Error: ', error);
};
2021-09-11 17:49:27 -04:00
}
}
2021-09-12 17:30:56 -04:00
var file = document.querySelector('input[type=file]')['files'][0]
var reader = new FileReader();
reader.readAsDataURL(file)
reader.onload=function() {
data.push(reader.result)
console.log(data)
var params = data.join("&");
var xhr = new XMLHttpRequest();
xhr.open("POST", postloc);
console.log(params);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.send(params);
};
reader.onerror = function (error) {
console.log('Error: ', error);
};
2021-09-11 17:49:27 -04:00
console.log(data);
2021-09-12 17:30:56 -04:00
2021-09-11 17:49:27 -04:00
}
function getBase64(file, form_elem, i, data, callback) {
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function () {
callback(form_elem, i, data, reader.result);
};
reader.onerror = function (error) {
console.log('Error: ', error);
};
}