Quiero recibir la imagen de blob almacenada en la columna 'menuImg' de tipo longblob y ponerla en la etiqueta img con el id 'img'. ¡Ayúdame!
['/admin/getMenuImg' Fuente del enrutador]
router.get('/getMenuImg', function (req, res) { //var menuNo = req.body.menuNo; var query = `SELECT menuImg FROM menu WHERE menuNo = 1`; connection.query(query, function (error, result) { if(error) { console.log("error ocurred: ", error); res.json({ "code": 400, "result": "error ocurred" }) } else { console.log("get menuImg success"); res.json({"code": 200, "result": "get menuImg success", "menuImg": result[0].menuImg}) } }) })[fuente html]
<body> <img id="img" width="400" height="400"> </body> <script> $.ajax({ url:'/admin/getMenuImg', // Maybe this is wrong cache:false, xhr:function(){ var xhr = new XMLHttpRequest(); xhr.responseType= 'blob' return xhr; }, success: function(data){ var img = document.getElementById('img'); var url = window.URL || window.webkitURL; img.src = url.createObjectURL(data.menuImg); }, error:function(){ } }); </script>