0

I'm Currently building a polling app where real-time data are being pulled from the database.

I have figured out how to insert data into the database using Ajax without page refreshing but stuck on displaying those data in real-time without page refreshing using Ajax.

This is my code for inserting data:

$.ajax({

         type: "POST",
         url: "save.php",
         data: {
                color1: color1, color2: color2
            },
         success: function(data){
              console.log(color2);
         }
});

please help me in solving this problem. Thanks.

  • 2
    Possible duplicate of [jQuery Ajax POST example with PHP](https://stackoverflow.com/questions/5004233/jquery-ajax-post-example-with-php) – netwer May 21 '18 at 16:22
  • And make sure to learn how to use the [**Network Tab**](http://stackoverflow.com/a/21617685/2191572) – MonkeyZeus May 21 '18 at 16:26

1 Answers1

0

You can take a look a jQuery reference on how to retrieve data using get.

$.get( "load-data.php", 
    function( data ) {
    console.log(data);
})
  .done(function() {
    //do something is successful
  })
  .fail(function() {
    //do something is there is an error
  })
  .always(function() {
    //do something no matter what
  });
Koji D'infinte
  • 1,309
  • 12
  • 20