How to Create a QR Code Image in JavaScript

Cloudmersive
2 min readMay 17, 2021

--

When we think of barcodes, it’s usually the traditional UPC-A code that we see in our everyday retail transactions that comes to mind. During the pandemic however, the QR code has also made itself a staple of modern business transactions by providing a versatile and touchless option to share basic and complex information alike. If you’re looking for a simple way to generate a QR code without the hassle of building it out, you can use the following API in JavaScript to automatically encode free-form text information and generate a PNG file of the QR code.

We will start the process by installing the jQuery library:

bower install jquery

Then, we can input the free-form text and our API key into the following code:

var settings = {
"url": "https://api.cloudmersive.com/barcode/generate/qrcode",
"method": "POST",
"timeout": 0,
"headers": {
"Content-Type": "application/x-www-form-urlencoded",
"Apikey": "YOUR-API-KEY-HERE"
},
"data": {
"0": "<",
"1": "s",
"2": "t",
"3": "r",
"4": "i",
"5": "n",
"6": "g",
"7": ">"
}
};
$.ajax(settings).done(function (response) {
console.log(response);
});

The API Key for this function can be retrieved at no cost and with no commitment on the Cloudmersive website; this will provide you with access to 800 monthly calls across any of our APIs.

--

--

Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.