Saturday, 20 May 2017

appending image with websockets to pug file

I'm creating a small app with node.js and have stumbled upon a problem. I am trying to send an img to all users from my admin account. The problem is I can't seem to show my image through javascript appending to the div I made . Is it because I'm working with pug that it doesn't render my image?

My admin side

document.querySelector('#Function1').addEventListener("click", function (e) {
    alert('hi mom');

    primus.write({message: 'function1'});
    //console.log(id);
    e.preventDefault;
});

My client side

var image ="images/logo.png";

primus.on("data", function (data) {
    if(data.message != undefined) {
        if(data.message == 'function1') {
            document.querySelector("#functionShow").append("<img src="+image+"/>");
        } else {
            console.log('i fucked up');
        }
    }
});

This is the end result shown

welkom Hanna

<img src=images/logo.png/>


via Chandrakant

No comments:

Post a Comment