我正在尝试使用从带有 ajax 的 php 处理程序获取的图像路径更改图像源。
我正在捕捉的是:“img/blah.jpg”
这是我的ajax:
$('.name').click( function() {
//var e = $(this).attr('src','img/no.png'); //this works
$.ajax({
url:'handler.php?blahid='.$idnum,
type:"GET",
success: function(data)
{
var f = $(this).attr("src", data); //$(this) is the image I click on that I want to replace
console.log(f);
},
error: function(jqXHR, textStatus, errorThrow)
{
debugger;
}
})
}
当我单击要更改的图像时,ajax 就完成了它的工作。也许我以不正确的方式使用响应数据。我使用控制台日志查看我得到了什么,它返回了一个对象。所以我想我的问题是:我现在正在做的事情不起作用,我不知道为什么。如果你想让我澄清任何事情,请告诉我。提前致谢。