我有一个php页面,吐出从instagram帐户提供的个人资料图片网址。例如,如果你去..
.com/ajax_check_instagram.php?username=tom页面将返回
http://instagram.com/profilepic.png然后我有一个ajax调用,为了让sucess函数更新一个图像源,我尝试对它进行操作。
//Add a loading image in the span id="availability_status"
var link = '';
$.ajax2({ //Make the Ajax Request
type: "POST",
cache: false,
dataType: "json",
url: "/ajax_grab_instagram.php", //file name
data: "username="+ username, //data
success: function(server_response){
link = server_response;
$("#profilepic").attr("src","link");
}
});
}我该如何格式化server_response行和jquery行?
发布于 2014-11-04 01:09:01
在PHP/AJAX文件中,您需要返回图片的URL。然后在你的jQuery AJAX请求中...
除了将link封装在双引号中之外,它几乎是原样的。
$.ajax({
type: "POST",
cache: false,
dataType: "json",
url: "/ajax_grab_instagram.php",
data: "username="+ username,
success: function(response) {
$("#profilepic").attr("src",response);
}
}); 在我的示例中,我已将其更改为response。
发布于 2014-11-04 01:49:51
link是一个变量,而不是一个字符串。
$("#profilepic").attr("src", link); // link should not be in quoteshttps://stackoverflow.com/questions/26719128
复制相似问题