Reputation: 39
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.
Upvotes: 3
Views: 3119
Reputation: 1345
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.
Upvotes: 2