如何追加和图像在另一页回显

时间:2014-03-23 19:13:50

标签: php jquery

我正在使用表单插件(确切地说是jQuery表单插件),我想知道如何将处理页面中回显的数据附加到我想要追加的文件是图像文件。

jQuery的:

$(document).ready(function () {
    var options = { 
        target:'.prof_img',   // target element(s) to be updated with server response 
        url:'upload_profile_pic.php',
        type:'POST', 
        success:function() { 
            $("#theater_outer").hide();
            $('a[class="prof_img"]').empty(); //where prof_img is the div i want to empty and append the image inside
            $('a[class="prof_img"]').append(data);
        } 
    };      
    $('#upload_profile_photo').ajaxForm(options); 
}) 

2 个答案:

答案 0 :(得分:0)

您需要success回调function

中的数据参数
$(document).ready(function () {
     var options = { 
         target:'.prof_img',   // target element(s) to be updated with server response 
         url:'upload_profile_pic.php',
         type:'POST', 
         success:function(data) { 
             $("#theater_outer").hide();
             $('a[class="prof_img"]').empty(); //where prof_img is the div i want to empty and append the image inside
             $('a.prof_img').append($(data));
         } 
     };      
     $('#upload_profile_photo').ajaxForm(options); 
 });

答案 1 :(得分:0)

尝试以下方法:

$(document).ready(function () {
    var options = { 
        target:'.prof_img',   // target element(s) to be updated with server response 
        url:'upload_profile_pic.php',
        type:'POST', 
        success:function(img) { //img should be the server side response
            $("#theater_outer").hide();
            $('a.prof_img').html(img); //replace inner html with the image html
              //^ simpler class based selector
        } 
    };      
    $('#upload_profile_photo').ajaxForm(options); 
});