2013-07-29 6 views
0

그냥 PHP 스크립트 파일의 responseText를 div에 추가하려고합니다. div의 내용을 바꾸지 말고 responseText를 기존 div 내용에 추가해야합니다. responseText는 태그입니다.ajax와 jquery를 사용하여 PHP 파일에서 div로 응답 태그를 추가하는 방법

$(document).ready(function() { 
var options = { 
    beforeSend: function() { 
    $("#progress").show(); 
    //clear everything 
    $("#bar").width('0%'); 
    $("#message").html(""); 
    $("#percent").html("0%"); 
    }, 
    uploadProgress: function(event, position, total, percentComplete) { 
    $("#bar").width(percentComplete+'%'); 
    $("#percent").html(percentComplete+'%'); 
    }, 
    success: function() { 
    $("#bar").width('100%'); 
    $("#percent").html('100%'); 
    }, 
    complete: function(response) { 
    $("#message").append("<font color='green'>"+response.responseText+"</font>"); 
//DOESN'T WORK  
     }, 
     error: function() { 
     $("#message").html("<font color='red'> ERROR: unable to upload files</font>"); 
    } 
}; 

$("#uploadForm").ajaxForm(options); 
}); 
+0

대신 responseText를 추가하기 위해 메시지 div의 내용을 대체한다는 의미입니다. –

답변

1

beforeSend에서이 줄 :

$("#message").html(""); 

플러스 라인이 완전한 에서 : 대신 APPEND의 콘텐츠 교체로

$("#message").append("<font color='green'>"+response.responseText+"</font>"); 

역할을합니다. 먼저 의 줄을 제거한 후을 보내주십시오.

+0

고마워요! 그것은 작동합니다, 나는 그것을 간과했습니다. –