I used an API in API Ninjas that gives you QRCode of the data you give them, but unfortunately, my code isn’t working! Its giving me an error!
const qrInput = document.getElementById("qr-input");
const qrButton = document.getElementById("qr-button");
const qrImage = document.getElementById("qr-image");
qrButton.addEventListener("click", generateQR);
async function generateQR() {
let api = `https://api.api-ninjas.com/v1/qrcode?data=${qrInput.value}&format=png`;
let request = new Request(api, {
method: 'GET',
headers: {
'X-Api-Key': '###APIKEY###',
'Accept': 'image/png'
},
contentType: 'application/json',
success: function(result) {
console.log(result);
},
error: function ajaxError(jqXHR) {
console.error('Error: ', jqXHR.responseText);
}
})
let y = await fetch(request);
console.log(y.json());
}
I tried everything that API Ninja instructed (this is the link: https://api-ninjas.com/api/qrcode)