2014-11-03 52 views
0

我有一个php页面,它从提供的instagram帐户中提取个人资料图片URL。例如,如果你去..使用AJAX从php页面收集链接并更新图像

.com/ajax_check_instagram.php?username=tom 

的页面会返回

http://instagram.com/profilepic.png 

我那么有哪些即时通讯试图操纵这样的研制成功功能更新图像源Ajax调用。

 //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行?

回答

0

在你的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

+0

您可能还需要在这一点上也验证URL! – 2014-11-03 17:09:54

+0

我以为我很接近,它看起来不像这实际上是为我工作:( – SlowPoke 2014-11-03 17:27:48

+0

它看起来像服务器发送回链接确定,但阿贾克斯没有得到应用? – SlowPoke 2014-11-03 17:28:35

0

链接是一个变量,而不是一个字符串。

$("#profilepic").attr("src", link); // link should not be in quotes 
相关问题