Update Image source from AJAX success function

前端 未结 3 362
萌比男神i
萌比男神i 2021-01-13 16:28

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

相关标签:
3条回答
  • 2021-01-13 16:38

    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);
            }
        });
    
    0 讨论(0)
  • 2021-01-13 16:42

    Try .prop()

    success: function (data) {
        $('#mstatus').html(data.matchstatus);
        $('#myimage').prop('src', 'VAlue'); //change image src
    }
    


    Read .prop() vs .attr()

    0 讨论(0)
  • 2021-01-13 16:58
    $('#myimage').attr('src', '/imagePath/');
    
    0 讨论(0)
提交回复
热议问题