0

I have a default image which is loaded in the HTML. Then i check if a personal image exists with an ajax request, the request is succesful however it cannot set the new image src. The image loaded from HTML is always displayed. The code to set the new image src works if it is outside the ajax request. This is my code:

 <img id="imageid" src="media/default/slider.jpg" alt=""/>
 ...
 <script type="text/javascript">





$.ajax({
    url:'media/' + loginmail + '/slider.jpg',
    type:'GET',
    dataType: "image/gif",
    error: function()
    {


    },
    success: function(data)
    {

        alert("success" );

        $('#imageid').attr('src', "media/" + loginmail +    "/slider.jpg");           
    }
});

Thank you. EDITED:

I really do not know if it changes something but i am using the http://slimimagecropper.com/ Plugin.

 <div id="my-cropper" class="slim" style="width:1200px; height: 300px; border:0;"
data-service="async.php"
data-fetcher="fetch.php"
data-ratio="12:3"
data-size="1200,300"
data-label="Insert here your image">   
<img id="imageid" src="media/default/slider.jpg" alt=""/>
<input type="file" accept="image/jpeg, image/png" name="slim[]"/>

2 Answers2

0

I replace the image source in ajax with random image url and it works. check here

Also write all your inside this function.

$(function(){});
  • thank you, i tried replacing with http://lorempixel.com/400/200/sports/Dummy-Text/. It doesn't work. – GIANLUCA MONICA Apr 05 '17 at 11:05
  • replace it where you're setting the `src` of image i.e. `$('#imageid').attr('src', "http://lorempixel.com/400/200/sports/Dummy-Text/"); ` –  Apr 05 '17 at 11:09
  • thank you, it works on fiddle, i am thinking the problem is the plugin http://slimimagecropper.com/ that i use. – GIANLUCA MONICA Apr 05 '17 at 11:15
0

remove below line of code

dataType: "image/gif",
Vindhyachal Kumar
  • 1,613
  • 2
  • 20
  • 26