从AJAX成功函数更新图像源 [英] Update Image source from AJAX success function

查看:74
本文介绍了从AJAX成功函数更新图像源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用来更新AJAX成功函数中的Label值,如下所示,但我需要知道我将如何应用此方法来更改/更新< img id的src =myimagesrc =/>

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);
    }
});


推荐答案

使用jquery,你可以像<$ c $一样使用c> $(#myimage)。attr('src','img url');

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

假设你有回应 data.imgsrc 那么它应该是, $(#myimage)。attr(src,data.imgsrc);

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);
        }
    });

这篇关于从AJAX成功函数更新图像源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆