Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajax auto update when db updated

Tags:

ajax

mysql

I need my text to auto update when the mySQL database is updated. Could someone please help with this? I've looked a lot and no post says what I need, i'm new to ajax and don't know much about it. All I know is HTML, CSS, PHP and javascript.

like image 623
Jayden McCoy Avatar asked Jan 25 '26 19:01

Jayden McCoy


1 Answers

First of all, you might wanna check jQuery. It'll be very simple if you know javascript, and it'll make your development a lot easier.

Then you need to check how an ajax call is implemented with jQuery. Again, really simple, here's an example.

test.php

$var1 = $_POST['key'];
$var2 = $_POST['key1'];

//Some code here

echo 'Test finished'; // This is returned to the ajax call

JAVASCRIPT

$.ajax({
         url:   '/test.php', 
        type:   'POST', /*Method, POST or GET depending on your needs*/
       async:  true, /*This makes the ajax call asyncronously or not*/
        data: {'key':value,'key2':value2},/*data to send*/
     success: function(result){  /*Return from PHP side*/

            /* result contains the data replied from the PHP script. */
            alert(result);

        }
});

If you want to replace some parts of your HTML you might wanna check functions like, append, after, before, prepend and html,etc. Also learn something about JSON, it's a data format. Really simple and yet magnificent

Hope this helps you! It looks like homework, but you'll ace it in no time, you'll see.

like image 50
Nicolás Torres Avatar answered Jan 27 '26 09:01

Nicolás Torres



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!