PHP Front To Back [Part 18] – PHP & AJAX



In this video I will show you how we can use PHP and AJAX together to build a simple suggestion engine for a form input

CODE: Code for this video

EDUONIX COURSES: Please use affiliate links from website below

SUPPORT: We spend massive amounts of time creating these free videos, please donate to show your…

, , , , , , ,

35 thoughts on “PHP Front To Back [Part 18] – PHP & AJAX

  1. Brad, I don't understand why you used the array like that. I learned a lot of things from you. but in this video I figured something. the codes you used same in the w3tutorials.com. you I think you better. and I want to say another thing. if we use the $people array like this $people = ["name,"name,"name,"………]; it gives same things. whatever I just want to say it. thanks for video.

  2. This was a nice stretch and overall Challenge. I'm glad I understand enough of the fundamentals to pick up what was taught during this lesson. This is my first time working with AJAX and live Server Response/Request Cycles. I really picked up a lot. Not sure if I could do it on my own, but I was able to follow exactly what you did, and could definitely adapt the code to another set of data and tweak things. Thank you for this. You've help me immensely!

  3. Hi, I am having a small problem here. Nothing is showing when I typed in the box and when I pressed f12 to trace the error, it showed showSuggestion is not defined. I know for sure I have defined it and followed the instruction just as taught in this video. What do you think the problem could be?
    Thanks

  4. This was really helpful! I've been learning PHP and now I'm learning AJAX and advanced javaScript stuff, and this was eaxctl what I needed, learning how to bridge the two together. Looking forward to seeing your video on how to do the same with MySQL =)

    Thanks a ton man. I'll make sure I check out more of your stuff too.

  5. Can you post the code? My code isn't working and i have been trying to find out why… when i type it's saying i have an error in my suggest.php file outside of my php tags…Can you fix the link in the description please…Thank you Brad.

  6. Ok, you completely lost me here, Brad! I have been able to follow your tutorials and understand the code until now but this video was totally out of my depth! I'll try to re-watch it again and also move on to the next video, hoping some things will click eventually.

  7. hii , thanks for all effort at this series .. but i tried it but didn't work without any error , it don't show the suggestions !
    i think there are a problem at the connection or at getting the request , can any one help !? thanks..

  8. this was a bit complicated, but I think I got it after thinking about it. At first I didn't understand where the response was coming from. Like I see in the javascript response text but I didn't see responsetext in the php. Now I understand that it's the echo that's sending the data over to the javascript because that is the server's response. I'm a dummy. Took me a while to get that.

  9. hi can any one help me on this tutorial plz?? i've tried it but its not working i've been checking and re checking but don't seems to have miss something.
    this is the index.php code

    <!DOCTYPE html>
    <html>
    <body>
    <head>
    <title>Search User</title>
    <link rel="stylesheet" href="http://bootswatch.com/cerulean/bootstrap.min.css">
    <script>
    function showSuggestion(str){
    if(str.length == 0){
    document.getElementById('output').innerHTML = '';
    }else {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function(){
    if(this.readystate == 4 && this.status == 200
    ){
    document.getElementById('output').
    innerHTML = this.responseText;
    }
    }
    xmlhttp.open("GET", "suggest.php?q="+str, true);
    xmlhttp.send();

    }
    }
    </script>

    </head>
    <body>
    <div class="container">
    <h1>Search Users</h1>
    <form>
    Search Users: <input type="text" class="form-control"
    onkeyup="showSuggestion(this.value)">
    </form>
    <p>Suggestions: <span id="output" style= "font-weight:bold"></span></p>
    </div>

    </body>
    </html>

    this is the suggest.php code
    <?php
    $people[] = "john";
    $people[] = "paul";
    $people[] = "george";
    $people[] = "ringo";
    $people[] = "sara";
    $people[] = "aurore";
    $people[] = "guichard";
    $people[] = "aldo";
    $people[] = "marienoel";
    $people[] = "melanie";
    $people[] = "milene";
    $people[] = "olivia";
    $people[] = "olivier";
    $people[] = "derek";
    $people[] = "rachelle";
    $people[] = "jose";
    $people[] = "amanda";
    $people[] = "katie";
    $people[] = "malcom";
    $people[] = "katie";
    $people[] = "brad";
    $people[] = "mary";
    $people[] = "mike";
    $people[] = "farrah";

    $q = $_REQUEST['q'];
    $suggestion = "";

    if($q !== ""){
    $q = strtolower($q);
    $len = strlen($q);
    foreach($people as $person){
    if(stristr($q, substr($person, 0, $len))){
    if($suggestion === ""){
    $suggestion = $person;
    }else{
    $suggestion .= ", $person";
    }
    }
    }
    }
    echo $suggestion === "" ? "No Suggestion" : $suggestion;

    //can any one tell me what i've miss plz??

  10. You're a great teacher!!! Keep up with the good work! Thank you for making this free course! I wish to see more about OOP and Mysqli together, PHP is such a beautiful language…

Leave a Reply

Your email address will not be published. Required fields are marked *