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

Поділитися
Вставка

КОМЕНТАРІ • 124

  • @gogvale
    @gogvale 4 роки тому

    I'm impressed. No importing libraries, setting routes, exposing variables… Just a single plain php file with a nested if block and an echo. Bravo!👏👏👏

  • @LucasPedroniG
    @LucasPedroniG 7 років тому +24

    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...

  • @collo5070
    @collo5070 5 років тому +1

    I see things are getting tougher and tougher as I go in depth with PHP, but I'm glad that at the end of the day, at least I've learned something new all thanks to you. For example now I know I can use the console logs to identify errors in my code. So thanks man...

  • @svenbtb
    @svenbtb 7 років тому +6

    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.

  • @busyrand
    @busyrand 6 років тому

    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!

  • @zunutube
    @zunutube 5 років тому +2

    if anyone has issues understanding what's going on in suggest.php. I suggest you, debug the code. Set the variables in debug watch and you will know what are the values as it loops through the array. Keep in mind the functionality of substr() and stristr() functions. I set two variables like below inside the loop and set these variables in debug watch to check values of these variables.
    $substr = substr($person, 0, $length);
    $stristr = stristr($q, $substr);
    Debugging the code will give you a thorough understanding of how it works

  • @deveagle6193
    @deveagle6193 5 років тому

    It's SO nice to see SOMEONE finally using VanillaJS instead of stupid jQuery. Nearly all employers seem to favor VanillaJS. Thank you!

  • @CarolinaQVargas
    @CarolinaQVargas Рік тому

    So glad I found your channel! Thank you!

  • @fury_uri
    @fury_uri 3 роки тому +1

    Another great video, Brad. I think it would've been helpful to explain your PHP conditional logic a bit more. I was okay with the AJAX since I'd covered it in a different course recently. I will pause the video, look at your code and try to figure out how it's all working.
    Edit: Took me about 5 minutes to look up the PHP functions/methods and figure out the conditional logic! :-)

  • @ravimukti690
    @ravimukti690 5 років тому +3

    Once again, you're the man brad

  • @torleifv3335
    @torleifv3335 4 роки тому

    This is exactly what I've been looking for to get a filter system for my website, thanks Brad!

  • @allin6074
    @allin6074 5 років тому

    Best Tutorial vids on UA-cam keep up the great work bro

  • @mushfiqfuad249
    @mushfiqfuad249 3 роки тому

    My two favorite UA-cam TEACHERs are Brad Traversy and Tim Buchalka from "The Learn Programming Channel"

  • @MrScrosb
    @MrScrosb 6 років тому +38

    after spending 30 minutes wondering why my code wasn't working, I realized the "s" in this.readystate wasn't capitalized.

    • @estevesazeiteiro
      @estevesazeiteiro 6 років тому +2

      Thank you.

    • @MsSuyash1995
      @MsSuyash1995 6 років тому +7

      After reading your comment, I realized that I have added a 's' in 'readyState'... So, thank you so much for unintentionally helping me...

    • @taariqq
      @taariqq 6 років тому +4

      Now you will remember this for a long time :)

    • @marcinrakowski1299
      @marcinrakowski1299 5 років тому

      lol, same here

    • @burakdizel8961
      @burakdizel8961 5 років тому

      Thanks man

  • @king-manu2758
    @king-manu2758 4 роки тому

    All of this is really cool and I wish i could even aspire to be able to come up with stuff like this on my own but for now it just goes way over my head.

  • @RameenFallschirmjager
    @RameenFallschirmjager 5 років тому

    Awesomeness has been redefined! this is great! Ajax is god!

  • @ahmadabdulaziz9696
    @ahmadabdulaziz9696 7 років тому +2

    Thanks Man have been waiting for days for the next video

  • @sandeshthapa2738
    @sandeshthapa2738 4 роки тому

    Lifesaver Brad

  • @brettgattinger3338
    @brettgattinger3338 4 роки тому

    To anyone having trouble getting their code to work, I would suggest you check all your conditionals and make sure your using the right operators, For example I had been using '==' in the suggest.php where I should have been using '==='

  • @Elninomani70
    @Elninomani70 6 років тому

    I wish I could like your videos 100000000000000 times

  • @forethiocodingstaff
    @forethiocodingstaff 6 років тому

    All your tutorials are very interesting, continue more than this. Thank you...>

  • @HoanNguyen-fc8vb
    @HoanNguyen-fc8vb 4 роки тому

    Thank so much for the tutorial. You are the best!

  • @AntonioSantos-xk5zu
    @AntonioSantos-xk5zu 7 років тому

    This is exactly what I needed right now! Thanks!

  • @zk9379
    @zk9379 7 років тому +15

    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.

    • @hanzlaahabib
      @hanzlaahabib 6 років тому +2

      don't worry its easy you will get it

    • @bentaylor10
      @bentaylor10 5 років тому +4

      yeah he shouldnt have added the javascript when intoducing the topic for the first time, kinda overcomplicated the whole process.

    • @prashantsingh7025
      @prashantsingh7025 5 років тому

      @@bentaylor10 ajax start and end with javascript dear

    • @prashantsingh7025
      @prashantsingh7025 5 років тому

      php is only used in url section of ajax

    • @paulburger9904
      @paulburger9904 5 років тому +3

      You are probably confused by the JavaScript. Take a break and do some JavaScript. It is basically the code that runs in the browser or 'front-end'. It goes inside the tags. What the JavaScript code is doing is making a request to the 'back-end', which is the .php file on the server. The server handles the request and sends it back to the 'front-end'/web-browser. :)

  • @mackensonreginaldmichel399
    @mackensonreginaldmichel399 Рік тому

    Nice video. A question: is JSON.parse the same as this.responseText? When to use either?

  • @stuknowlton477
    @stuknowlton477 4 роки тому

    Wow Brad thank you this is great!

  • @coredatallc5671
    @coredatallc5671 5 років тому

    Great tutorial. Looking forward to the MySQL PDO example, based on PDO delusions db connection using OOP.

  • @hussain5755
    @hussain5755 7 років тому

    Love and respect for ma man brad

  • @zlackbiro
    @zlackbiro 5 років тому

    You can get that on easiest way! inside php file put the simple Array with the
    $names = array("name1", "name2", "name3");
    and use php to loop true the names. One simple if inside with in_array() method to check is mached with the names in the array, else return no-suggestion matches. Its simple code with 5 lines of code. 😕 php is easier than JS.

  • @samysimon2062
    @samysimon2062 4 роки тому

    Great work, cheers !

  • @prospersikhwari5289
    @prospersikhwari5289 7 років тому

    big ups to this guy👌

  • @lifecyclevlog
    @lifecyclevlog 7 років тому

    Great Series ! Thank you !

  • @taariqq
    @taariqq 6 років тому

    very useful stuff.

  • @chimpionboy
    @chimpionboy 6 років тому

    Awesome. Did you by any chance hook this up to database.

  • @pepeback
    @pepeback 7 років тому +1

    thanks again

  • @ДанилЯдыкин-к9э
    @ДанилЯдыкин-к9э 5 років тому +1

    If you have in your array of people names like Jim and Jimmy add these lines to your code:
    if ($q===strtolower($person)){
    $suggestion=$person;
    }
    Because if you type Jimmy you still get Jim as a suggestion

  • @hanzalasaeed9797
    @hanzalasaeed9797 5 років тому +1

    Why do you add bootstrap to your code? Is it necessary? I don't know anything about bootstrap!

  • @АлексаМиловановић
    @АлексаМиловановић 5 років тому +1

    I think that Brad's suggest solution is confusing. We can use substring function and check if that part is same as query, but first we convert both to lower string.
    foreach ( $people as $person ) {
    if ( strtolower ( substr ( $person, 0, $len ) ) === strtolower ( $q ) ) {
    if ( $suggestion === "") {
    $suggestion = $person;
    } else {
    $suggestion .= ", $person";
    }
    }
    }

    • @fury_uri
      @fury_uri 3 роки тому

      Okay, this is reassuring. I also thought/figured out that this might be another solution (comparing the values directly instead of using stristr() ). However, the benefit of stristr() is that it's already case-insensitive, so perhaps that's why Brad used it.

  • @arifarslanturk2951
    @arifarslanturk2951 4 роки тому +1

    if you want use fetchApi implement below
    function showSuggestion(str) {
    if (str.length === 0) {
    document.getElementById('output').innerHTML = '';
    } else {
    fetch(`suggest.php?q=${str}`, {method: 'GET'})
    .then(res => res.text())
    .then(text => document.getElementById('output').innerHTML = text)
    .catch(err=>console.log(err))
    }
    }

  • @uboat46
    @uboat46 7 років тому

    Nice!

  • @Osteele
    @Osteele 6 років тому +2

    Way over my head. But thanks anyway. Appreciated as always.

  • @joeyGunz1-w1r
    @joeyGunz1-w1r 3 роки тому

    Trying to do it with fetch API is a pain in the ass, is it still commonly used with AJAX ?

  • @miku4j
    @miku4j 4 роки тому

    I'm gonna use fetch or axios instead

  • @MohamedGamal-hr2si
    @MohamedGamal-hr2si 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..

  • @castmixer12
    @castmixer12 7 років тому +3

    This part was really tough for me. I guess because I don't know javascript.

    • @TraversyMedia
      @TraversyMedia  7 років тому +2

      Yeah I figured it would be. I just wanted to do something with Ajax. It was a little hard to explain though.

    • @castmixer12
      @castmixer12 7 років тому +1

      Actually, I'm new to web development that's why I don't know javascript.
      But seriously Brad, you are doing great. (Y)

    • @VentusLionheart
      @VentusLionheart 7 років тому +1

      You should really consider learning Javascript first before learning PHP. A whole new world opens up with Javascript and a server-side language like PHP.

    • @Benjamin-vo6qk
      @Benjamin-vo6qk 7 років тому +1

      Yep, it was tough for me too. I have javaScript knowledge but very little. I would suggest printing the codes to the paper and analyzing the code, adding arrows etc just to understand what or where was those particular code was targeting. Sorry if my English is not that good though but I hope this one helps. Good luck to all!

  • @Joseph-do9ue
    @Joseph-do9ue 3 роки тому

    Need more content

  • @samuele.caruso
    @samuele.caruso 6 років тому +2

    Stop the course here, and start to learn JS

  • @_origin5858
    @_origin5858 2 роки тому

    can someone explain how the this.value works ? Is value a property ?

  • @rolineo
    @rolineo 4 роки тому

    What about this example in CodeIgniter?

  • @100k-h7q
    @100k-h7q 5 років тому

    I did all along the full course Back to Front tutorials .. but this one is really confusing and not work for me as well.

  • @aubreydigital
    @aubreydigital 2 роки тому

    i know this is pretty old but i cant get your code link to go anywhere.. i seem to have everything correct but i guess not because im getting the correct suggestions back in the response, i can see from the network tab, but its not outputting to the DOM...

    • @aubreydigital
      @aubreydigital 2 роки тому

      jk 😅 i didnt capitalize the S in this.readyState...

  • @BigKmaniac
    @BigKmaniac 6 років тому

    Is there a 16.zip ? I went back over surrounding zips and it jumps from 15 to 17. I admit I haven't read the threads so please forgive me if someone has pointed out the file ...

  • @anthonyleong3011
    @anthonyleong3011 6 років тому

    Hi can we have this connect to db fetch db from MySQL

  • @sumanmodak7859
    @sumanmodak7859 5 років тому

    first they say u can get a job with html,css and a little bit of javascript knowledge. But then suddenly php happens..we learned this. Now they're saying you have to know node.js,dom,react.js, Ajax, php frameworks ,,css frameworks,Mysql,,,algorithm.but still you can't get a job.You need to know more..But still not get a job..and one day we will die.....But still we need to learn new technologies..But don't expect job.

  • @stas8669
    @stas8669 6 років тому

    I wrote the same code but in output the hole array after a first letter name

  • @kaytech8153
    @kaytech8153 4 роки тому

    after i made the request i am getting undefind values

  • @1234zaptor
    @1234zaptor 6 років тому

    I'm having issue with this.. Failed to construct 'XMLHttpRequest': Please use the 'new' operator, this DOM object constructor cannot be called as a function.

    • @JoshuaGordon123
      @JoshuaGordon123 4 роки тому

      Did you use the correct syntax for this line:
      var xmlhttp = new XMLHttpRequest();
      ?
      Make sure you're referencing xmlhttp in the commands below it, and not xhttp.

  • @ChowChannel1
    @ChowChannel1 7 років тому

    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.

    • @4seth
      @4seth 6 років тому

      Check the details

  • @your_utube
    @your_utube 4 роки тому

    Brad I like your videos and they have taught me a lot. I have however found a subtle BUG in your code in the suggest.php code.
    CHANGE THIS CODE if (stristr($q, substr($person, 0, $len))){
    TO THIS CODE if (stristr(substr($person, 0, $len), $q )){
    The order of comparison is significant. if you don't then be prepared to get weird behaviour once the list that is suggested gets wittled down as you continue to type in characters. I find that if I TYPE in XXXXyyy and get suggestions like XXXXyy and XXXXyyyb, it wil still keep on displaying XXXXyy even though the last character I type was a 'y'. It seems to not properly compare the item typed against the list. By the time you type in XXXXyyyb, your're stil sitting with XXXXyy in the list. I tested this on a list of a few thousand string items. It works excellent once the bug is removed. I think you worked on a short list for the video, so you probable have not found the bug, but it does become annoying.
    I changed the order passed to the 'stristr' function to: Searched string as first param and SearchedFor (which they call the needle) as the second.. problem solved...
    Hope it helps someone. I know I am a few years late, but this is what it is. Thanks for great videos.

  • @tahasoft1
    @tahasoft1 5 років тому

    Thanks Brad. I rewrote this code easiest and simple modern way. To download:
    www.mediafire.com/file/d40pxh3b42v9xyz/ajax_search.zip/file

  • @bharanidharanmaheswaran3407
    @bharanidharanmaheswaran3407 5 років тому

    Can anyone tell me when to use cookies while creating a website?

  • @t3ntube357
    @t3ntube357 4 роки тому

    from javascripter point of view, this was difficult to understand, the way PHP create API very easily it is not usual in javascript

  • @karthikkumar5341
    @karthikkumar5341 4 роки тому

    I missed a "=" and the whole thing almost didn't work.

  • @kaytech8153
    @kaytech8153 4 роки тому

    please someone should help me out........

  • @tayyababhutta7799
    @tayyababhutta7799 3 роки тому

    I dont understand how $len is working here...

  • @ovidiublaga1
    @ovidiublaga1 5 років тому

    When the child started crying at 11:25 I thought that my baby was crying...

  • @oguz-kagan
    @oguz-kagan 5 років тому

    ben gerizekalı mıyım

  • @igora50
    @igora50 7 років тому

    First

  • @successfulpeople
    @successfulpeople 7 років тому

    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

    • @successfulpeople
      @successfulpeople 7 років тому +1

      Finally found the problem. Believe it or not, it was because I put xmlhttp.open("GET", "suggest.php?q="+str, true);
      xmlhttp.send(); side by side with the closed braces instead of at the bottom of it.

    • @hanzlaahabib
      @hanzlaahabib 6 років тому

      good to know you resolved your problm

  • @RameenFallschirmjager
    @RameenFallschirmjager 5 років тому

    Awesomeness has been redefined! this is great! Ajax is god!

  • @x0rZ15t
    @x0rZ15t 7 років тому

    Nice!