I am trying to download (into memory) an image as an object firstm, and display it as a background of body.
here is what I have done:

var url = "www.example.com/image/image.jpg";
var imageObject;
$.ajax({
    type: "GET",
    url: url,
    datatype:"image/jpg",
    success: function (data) {
        imageObject = data;
        $("body").css("background", imageObject); // not working
        //$("body").css("background", "url("+url+")"); //same image data from the memory?
    }
});

I am pretty sure there is no problem on displaying an image on <img> tag in this way by changing src attr.
But how can I change the background using image object?

If I just put same url in to the background, will that be using same image data from the memory?

What data are you sending from the server back to the client? Also, you'll find that to actually get to the data, you should be referencing data.data in your case.

You can know for sure if you use your browser's dev tools (in chrome and IE hit F12) and analyze the data from the server.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.