2014-11-03 1 views
0

제공된 Instagram 계정에서 프로필 사진 URL을 뱉어내는 PHP 페이지가 있습니다. 예를 들어, 당신은 가면 ..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의 유효성을 검사 할 수도 있습니다. –

+0

나는 이것이 가까이에 있다고 생각했는데, 실제로는 나를 위해 일하고있는 것처럼 보이지 않는다. ( – SlowPoke

+0

서버가 링크 확인을 보내고 있지만 아약스가 적용되지 않는 것 같습니까? – SlowPoke

0

링크는 문자열이 아니라 변수입니다.

$("#profilepic").attr("src", link); // link should not be in quotes 
관련 문제