Set image content from ajax response

Ashwin

I am making a ajax request in jquery as below. This ajax request gets images dynamically. And the image is always different image depending on the value of num

$.ajax({
    type: "POST",
    url: "ABC.php?num=1",
    success: function(response) {
          if(response == 1) {
                //some code
          }
          else {
                // Here I am not able to set image content.
                $("#image").attr("src", "data:image/png;base64,' + response + '");
          }
    }
});

Is there a way to set image content using the response of the ajax request. Thanks.

Halcyon

You have some unneeded single quotes there. Use this:

$("#image").attr("src", "data:image/png;base64," + response);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

show image from ajax response

From Dev

Set Image in cardview from JSON response

From Dev

AJAX to change div content from PHP Response not working

From Dev

Jquery UI call ajax from dialog and show the response in the content

From Dev

Rendering mathjax content with data loaded from ajax response

From Dev

Updating HTML text and an image from an AJAX Call server response

From Dev

How can I set data's in twig from Ajax response

From Dev

Display Image in ajax response in a table

From Dev

Set Ajax response on jsp not working

From Dev

How to check if ajax response is javascript content type?

From Dev

Get and store cookie (from Set-Cookie) from an AJAX POST response

From Dev

set tabbed content to slide image

From Dev

set content header name in response in java

From Dev

Retrieving value from ajax response

From Dev

POST a response from API by AJAX

From Dev

AJAX stacks response from PHP

From Dev

POST a response from API by AJAX

From Dev

No response from localhost with ajax request

From Dev

ajax response from string to array

From Dev

Retrieving value from ajax response

From Dev

no response from ajax in when method

From Dev

Get response from AJAX/PHP

From Dev

Checking the response from an ajax request

From Dev

How to retrieve java Set and iterate over the values from response of ajax call?

From Dev

Setting response image of Ajax Request to img tag

From Dev

Update the src of image using ajax response

From Dev

Image caching from a HttpClient response

From Dev

Set radio button checked with AJAX response

From Dev

JQuery $.ajax set cookie and get html response