Get data from PHP using Ajax

I am trying to display PHP data with Ajax but I’m missing sth…
Here is my PHP code:

include 'connect.php';						
$stmt = $dbh->prepare("SELECT * FROM testimonials ORDER BY RAND() LIMIT 0,1");

while ($row = $stmt->fetch()){
     echo "<p>". $row['testimonial'] ."</p>";

and then some Ajax:

	function get_fb(){
        var feedback = $.ajax({
	type: "POST",
	url: "testimonials.php",
	async: false
	setTimeout(function(){get_fb();}, 5000);
	<div class="feedback-box"></div>

I wanr to display new content from my database, every 5 seconds.

Thanks a lot!


You have the script within <style> tags. That’ll need sorting.

Code-wise, something like this would be better:

function get_fb() {
    type: "POST",
    url: "testimonials.php",
  }).success(function(res) {

setInterval(get_fb, 5000);

This is untested, but hopefully you get the idea.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.