2013-07-29 50 views
0

我只想從我的PHP文件附加responseText到一個div。 div中的內容不應該被替換,但是responseText應該被添加到現有的div內容中。 responseText是一個標籤。如何將php文件的responseText附加到div與ajax和jquery

$(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

這意味着它會替換消息div中的內容而不是附加responseText。 –

回答

1

這條線beforeSend

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

加行這完整

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

充當內容替換,而不是追加。只需將中的行刪除之後發送即可。

+0

謝謝!它的工作原理,我忽略了這一點。 –

相關問題