Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update Image source from AJAX success function

I use to update Label values inside the AJAX success function like below, But I need to know how I'm going to apply this method to change/update "src" of an <img id="myimage" src=""/>

$.ajax({
    url: 'clmcontrol_livematchupdate',
    type: 'post',
    dataType: 'json',

    success: function (data) {

        $('#mstatus').html(data.matchstatus);
        // $('#myimage').... ?

    },
    complete: function () {
        // Schedule the next request when the current one has been completed
        setTimeout(ajaxInterval, 4000);
    }
});
like image 762
Dilukshan Mahendra Avatar asked Nov 21 '13 05:11

Dilukshan Mahendra


People also ask

Is Ajax successful deprecated?

ajax function is deprecated.

How do you reload the same page after Ajax success?

You can use the location. reload() method to reload or refresh an entire web page or just the content inside an element. The . reload() method can be triggered either explicitly (with a button click) or automatically.


2 Answers

Using jquery, You can use like $("#myimage").attr('src','img url');

Assume, you have response like data.imgsrc then it should be like, $("#myimage").attr(src, data.imgsrc);

$.ajax({
        url: 'clmcontrol_livematchupdate',
        type: 'post',
        dataType: 'json',

        success: function (data) {

            $('#mstatus').html(data.matchstatus);
            $("#myimage").attr('src','img url');

        },
        complete: function () {
            // Schedule the next request when the current one has been completed
            setTimeout(ajaxInterval, 4000);
        }
    });
like image 195
Krish R Avatar answered Sep 30 '22 08:09

Krish R


$('#myimage').attr('src', '/imagePath/');
like image 42
swt Avatar answered Sep 30 '22 06:09

swt