2016-10-04 6 views
0

で$変数を含めますは、私はアヤックスが行われたときの画像を返すようにしようとしていますが、私は応答してセッション変数を含める方法がわからない、これは私のコードでAjaxの成功機能

<?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(); 

そして、あなたのjavascriptに:その後、私はあなたがこのようprocess.phpでその画像のファイル名をエコーすることができます#new-image

答えて

4

のdiv内の画像$_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注入には注意が必要です。 .attr( 'src'、 'uploads/img /' + image).attr($( '#new-image')のようなものです。 '、' img-upload ')) ' – Phil

+0

@ vher2これはうまくいっている、問題はそれが新しいイメージを更新しないということです、私は新しいアイデアをリリースするためにF5を与えなければなりませんか? – GePraxa

+1

これは古い画像 '$ _SESSION ['sess_img']'です。 – vher2

関連する問題

 関連する問題