Welcome to this ZIMONH Tutorial In this tutorial we will be focusing on AJAX Ajax is extremely useful as it allows you
to trigger PHP without having to refresh the page What you will be needing is a local or hosted web server with PHP and that’s it. Ajax is part of the jqury library. So, you need to include this before any AJAX functions. Now that the AJAX library is included in our document we can call the AJAX function. The first time I used this function it was
a bit confusing so I will going trough this function step by step First we have the URL to the PHP file. Here is our PHP file Inside the PHP file we are going to put a simple echo. And second we have the success function which is a anonymous function that uses the data variable which we are going to output in an alert Let’s test. It seamed to be working. Now let’s add an error. this will also trigger an anonymous function and we are going to alert error We are going to mess up the URL And now when the function runs we get error. Now we are going to add some variables Ajax is extremely useful as you can add variables into your PHP file with a simple POST Here we add a method into our AJAX function. And we are going to add some variables. this is our pineapple variable and here we have our pen variable We link these to the PHP variables You can give these any name you want. And we are going to use these in our echo. Once the variable is added into your PHP file you can do whatever you want with it. We’re going to simply echo a combined version of these variables. Let’s test it. We are going to return pineapple and pen And here we get pineapplepen Now let’s do something a bit more fun. Inside of our success function we are going to add this if statement and based on the data we are going to return different images So lets test it. First we are going to use the pineapple variable. and second we are going to test the pen variable. And now we are going to combine them into pineapplepen and see what happens. Now if you find this project is to complicated or taking up to much time, Than you can always ask help from a professional like me. That concludes this video thanks for watching. I hope you found this tutorial helpful. I hope you are building something to make
the world a better place. And.. Good bye!