JavaScript code:
$(function() {
timer = setInterval( function () {
$.ajax({
url: "ip/img",
type: "get",
context : this,
cache : false,
error : function(request,status,error){
alert("code:"+request.status+"\n"+"message:"+request.responseText+"\n"+"error:"+error);
},
success:function(obj){
$("#imguri").html('<img src="'+obj.data+'">');
//$("#imguri").attr("src", obj.data);
console.log(obj.data);
}
});
}, 3000);
});
Print same data enter image description here:
My server code:
client.on("message", async(topic, message)=>{ // {"LED" : "ON"} or {"MOTER" : "ON"}
if(topic == "JPG")
{
var obj = message.toString();
app.get("/img", function(req,res,next){
res.set("content-Type", "text/json");
res.send(JSON.stringify({data : obj}));
});
console.log(obj);
}
}
Print different data:
How can I get a different value each time from http?