Pregunta

I just want to append the responseText from my php file to a div. The Content in the div should not be replaced but the responseText should be append to the existing div Content. The responseText is a Tag.

$(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); 
});
¿Fue útil?

Solución

This line in beforeSend:

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

plus line this in complete:

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

act as a content replacement instead of an append. Just remove the line in beforeSend.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top