由网友(乱吻)分享简介:我试图改变图像源的图像路上我从一个PHP处理程序使用Ajax获得。I'm trying to change an image source with an image path I'm getting from a php handler with ajax.什么我赶上是:IMG / blah.jpgWhat I...
我试图改变图像源的图像路上我从一个PHP处理程序使用Ajax获得。
I'm trying to change an image source with an image path I'm getting from a php handler with ajax.
什么我赶上是:IMG / blah.jpg
What I'm catching is: "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;
}
})
}
阿贾克斯,它的工作,当我点击我想改变形象。也许我用了不正确的方式响应数据。我用的控制台日志,看看我得到了什么,它返回一个对象。所以我想我的问题是:我在做什么,现在不工作,我不知道为什么。让我知道如果你要我澄清什么。先谢谢了。
The ajax does its job when I click on the image I want to change. Perhaps I'm using the response data in an incorrect way. I used console log to see what I got and it returned an object. So I guess my problem is: what I'm doing now is not working and I'm not sure why. Let me know if you want me to clarify anything. Thanks in advance.
推荐答案
使用
$('.publish').click( function() {
var self=this; // add this line
$.ajax({
url:'handler.php?blahid='.$idnum,
type:"GET",
success: function(data)
{
var f = $(self).attr("src", data); // use self instead of this
console.log(f);
},
error: function(jqXHR, textStatus, errorThrow)
{
debugger;
}
});
}
相关推荐
最新文章