Let's suppose you're sending data through ajax. The server will process it (PHP) and sends a feedback that you can grab using Complete: function(data) { //WRITE HTML TO DIV $('#somehing').html(data) }
The question is:
is there a way to modify data (edit, delete) before passing it to an html element?
Here's a simple example of what I mean :
//php side
echo 'Invalid email';
echo 'Enter your username';
echo 'fine';
echo 1;
echo 2;
// Jquery and Ajax
$.ajax({
type: 'POST',
url: 'render.php',
data:values,
complete: function(data) {
$('#something').html(data) /* all those messages in php will be printed
into #something including the numbers. how to delete or edit those numbers
from appearing in #something? */
}
});
Try this to remove the numbers like,
complete:function(data){
data=data.replace(/\d+/,''); // Regular expression without quotation marks.
// or you can replace the something text like
// $('#something').text(function(){
// return this.innerText.replace(/\d+/,'');
// });
alert(data);
}