A
A
Alexander2015-12-14 21:14:47
PHP
Alexander, 2015-12-14 21:14:47

How to get a PHP-generated image via ajax request and make it a background image?

There is a code that generates an image and displays it in the browser. For example img.php:

header ("Content-type: image/png");
imagepng($thumb);

I can insert this picture as a background, for example, like this:
<div style="background-url:(http://site/img.php)"></div>

It works. Is it possible to access the img.php file through an ajax request and insert the result of this request as a background in the div layer?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stalker_RED, 2015-12-14
@Stalker_RED

Get image, convert to data-uri, paste as background. stackoverflow.com/questions/20035615/using-raw-ima...
Are you sure that you need to get the image via ajax? Why are you not satisfied with the background-url, which does all this for you, and at the same time does not require the very best browsers?

D
Deodatuss, 2015-12-14
@Deodatuss

yes, at least http://ninochosekakoysayt.ru/image.some format, the main thing is that the server gives the file with the necessary headers

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question