Javascript 使用AJAX从php页面收集链接并更新图像
我有一个php页面,从提供的instagram帐户中弹出一个个人资料图片URL。例如,如果你去Javascript 使用AJAX从php页面收集链接并更新图像,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我有一个php页面,从提供的instagram帐户中弹出一个个人资料图片URL。例如,如果你去 .com/ajax_check_instagram.php?username=tom 页面将返回 http://instagram.com/profilepic.png 然后我有一个ajax调用,我试图操纵它,以便success函数更新一个图像源 //Add a loading image in the span id="availability_status"
.com/ajax_check_instagram.php?username=tom
页面将返回
http://instagram.com/profilepic.png
然后我有一个ajax调用,我试图操纵它,以便success函数更新一个图像源
//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");
}
});
}
如何格式化服务器响应行和jquery行?在PHP/AJAX文件中,您需要返回图片的URL。然后在jQuery AJAX请求中 它基本上就是这样,除了你有
链接
封装在双引号中
$.ajax({
type: "POST",
cache: false,
dataType: "json",
url: "/ajax_grab_instagram.php",
data: "username="+ username,
success: function(response) {
$("#profilepic").attr("src",response);
}
});
在我的示例中,我将其更改为
response
。链接是一个变量,而不是字符串
$("#profilepic").attr("src", link); // link should not be in quotes
我想我很接近了,但看起来这对我来说并不奏效:(看起来服务器正在发回链接,但ajax没有得到应用?你是在响应PHP页面的响应而不是返回?