How can I dynamically parse a content that was returned by the php file that ajax sends request to?
My code:
jQuery(function () {
var request = jQuery.ajax({
url: "ajax/db.php",
type: "POST",
data: {
addresses: '<?php echo implode(' * ', $addresses); ?>'
}
});
request.done(function (msg) {
jQuery("#response").append(msg);
});
request.fail(function (jqXHR, textStatus) {
alert("Request failed: " + textStatus);
});
});
ajax/db.php
<?php
echo 'hello';
sleep (5);
echo 'world';
What I want to achieve is displaying the ajax/db.php
file response dynamically - first append the hello
string into the #response
object and after 5 seconds of sleep it should append another piece of string - world
.
At the moment the code just appends the whole output after 5 seconds.
Is there anyway to make it work like a live-response?