2014-11-03 26 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