我用来更新 AJAX 成功函数内的标签值,如下所示,但我需要知道我将如何应用此方法来更改/更新 <img id="myimage" src=""/>
的“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,你可以像这样使用 $("#myimage").attr('src','img url');
假设,您的响应类似于 data.imgsrc
那么它应该类似于 $("#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);
}
});
关于javascript - 从 AJAX 成功函数更新图像源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20113291/