2016-10-04 2 views
0

나는 아약스가 완료 될 때 이미지를 반환 노력하고 있어요,하지만 난이 응답 세션 변수를 포함하는 방법을 모른다는,이 내 코드 포함

<?php 
// using time() as the cache buster, the image will never be cache by the browser 
// to solve it, you need to add condition that will check if the image has change or not. 
// or maybe you need to change the filename if it changes without adding a cache buster. 
echo $_SESSION['sess_img_chofer']."?v=".time(); 

그리고 당신의 자바 스크립트 : 그럼, 당신은 다음과 같이 process.php에서 해당 이미지 파일 이름을 에코 할 수 #new-image

답변

4

사업부 내에서 이미지 $_SESSION["sess_img"];를 표시합니다 코드 :

$(document).ready(function(){ 
    $("#process").click(function(){ 

    $.ajax({ 
     type: 'POST', 
     url: 'process.php', 
     success: function (image) { 
     $('#new-image').html($('<img>').attr('src', 'uploads/img/' + image).attr('class', 'img-upload')); 
     } 
    }); 
    }); 
}); 
+1

HTML 삽입시주의해야합니다. 나는 $ ('# new-image')와 같은 것을 쓸 것이다. empty() .attend ($ ('') .attr ('src', 'uploads/img /'+ image) .attr 'class', 'img-upload'))' – Phil

+0

@ vher2 이것은 잘 진행 중이며 문제는 새로운 이미지를 업데이트하지 않는다는 것입니다. 새로운 아이디어를 내놓으려면 F5를 사용해야합니다. – GePraxa

+1

이것은 오래된 이미지'$ _SESSION [ 'sess_img']'입니까? – vher2

관련 문제