Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Alexander Foster
Alexander Foster
4,725 Points

More PHP/jquery projects

Not entirely sure if this is the right place to make this suggestion but here it goes...hopefully some of you guys agree! I think Treehouse should put more project lessons for both jquery and php, perhaps both of them used together. I love the idea of making an online store and an interactive website, but i would like to see more projects using those languages in different ways.

For example it was mentioned that PHP is good for building forums, maybe a project that includes making a forum would be a good idea, then later on adding features in with jquery to make it interactive. Or perhaps make a whole track that takes you from building a static site, and taking that static site and making a robust web app that uses php and jquery, The site would be different from Smells like bakin obviously!

Also another thing I would like to see is AJAX lessons!!! Any of you want to see similiar things?

p.s. sorry for long thread and if i am breaking rules!

I give my vote!

Thanks for the short course!

12 Answers

Hi Alexander Foster,

AJAX is a topic that comes up often in the forums. I have put together a video that explains the very basics. The example uses PHP to do simple math through a form. Then we will take that form and use jQuery and AJAX to capture that form post and just update the results.

This should help get you started as well as give you a small test project to play around with. You can download all the files here. I hope this helps you out.

Have fun! Hampton

cc: Matthew Campbell

Matt Campbell
Matt Campbell
9,767 Points

Brilliant...thanks Hampton Paulk, something to get me started!

My pleasure. Let me know if you need more info Matthew Campbell.

Constantine Antonakos
Constantine Antonakos
9,741 Points

Is intval() the same as typecasting a variable with (int)?

Constantine Antonakos
Constantine Antonakos
9,741 Points

Also, I think the 'edit' function in the forums is buggy. I couldn't edit my original comment.

Also, don't you need an anonymous function (or at least a function) to be passed into jQuery's POST function as a second parameter?

I had a bit of a read and I think they are essentially the same. intval() allows for conversions to/from different bases (base 16 to base 10) etc.. and (int) casting does not. But they both essentially convert to an integer.

While looking into it, I did notice that (int) casting is purported to cost less in CPU than intval(). I can't vouch for that myself, but another consideration might be readability. There is a certain advantage to having what you want to convert clearly placed as an argument of a function. (int) could look a little disconnected at a glance.

PHP sometimes seems a little messy this way to my eyes. It seems to have evolved organically rather than planned in a regimented fashion. It's just an impression I get while learning it. I'm possibly not being fair.

I have a problem. I'm trying to grab user posts from a database and I did get it so that I could echo out individual post parameters but trying to do the following doesn't work. I also tried bringing up an alert with the selected element's inner html and it worked so I know I'm selecting it right I just don't know why the HTML in the append method isn't added to the page when I run this:

var jqhxr = $.post('scripts/show_more_posts.php', serializedData)

    //success
    .done(function (response){
      var obj = $.parseJSON(response);

      if (obj.post !== null) {
        $(".post_item:last-of-type").append("<li>"+obj.post['entry_path']+"</li>");
      }
    })

    //always
    .always(function(){
      $input.prop("disabled", false);
    });```

I also tried replacing the code within the condition with this and it worked, but I can't get the first one to work:
```javascript
console.log(obj.post['entry_path']);

I'm trying to use the information retrieved from my database to write another list item element after the one selected in the following code but it won't write the HTML when i run it. It shows the right information when I display the inner HTML of the selected element when I do this - console.log(obj.post['entry_path']); - so I"m not sure why this isn't working.

var jqhxr = $.post('scripts/show_more_posts.php', serializedData)

    //success
    .done(function (response){
      var obj = $.parseJSON(response);

      if (obj.post !== null) {
        //console.log(obj.post);
        //console.log(obj.post['entry_path']);
        $(".post_item:last-of-type").append("<li>"+obj.post['entry_path']+"</li>");
        //$(".posts li[id]:last-of-type").attr('class');
      }
    })

    //always
    .always(function(){
      $input.prop("disabled", false);
    });

Also i don't think the "edit" button on these posts works because when I clicked edit on my last post it deleted in instead and reposted a different one

An AJAX deep dive on treehouse must be cool.

Sven Lenaerts
Sven Lenaerts
4,644 Points

I agree with you. Would love to see this.

+1

+1

+1

Jeff Mattheson
Jeff Mattheson
6,686 Points

+1... nice video. Maybe not enough for a whole deep dive as stated, but there seems to me like there is room for expansion. I have tinkered with AJAX and got it working for my purpose. I didn't use JSON though, I'd like to learn more about that... especially how to return multiple rows of data to JS from a PHP MySQL lookup. Maybe I just need to learn more about JS and Jquery in general. Keep up the good work, I love learning this stuff.

Alexander Foster
Alexander Foster
4,725 Points

Hey thanks a lot for posting the video Hampton Paulk! It will be a perfect spot to starting learning some AJAX. Also it is comforting to know the staff is browsing around the forum and answering questions :)

Marc Casavant
PLUS
Marc Casavant
Courses Plus Student 7,417 Points

Ajax is pretty simple, so I can't imagine that an entire deep dive could be dedicated to Ajax alone. What would be really cool is a course on a js library like backbone or angular js. So we can learn to object orientate our Ajax calls and optimize the front end. :)

I was thinking the same thing. It would be good to have a track for rich client web applications involving one or more MV* frameworks. It paves the way for cross-platform mobile app development too which would also be very relevant.

Great video.

Actually, it's also nice to see the process of conversion from back-end to front-end/ajax. As I'm learning, I'm always thinking in terms of implementing solutions using multiple methods. PHP back-end, Python back-end, Rich client Javascript/AJAX etc.. as I'm interested in increasing flexibility as well as learning specific methods. And given that best practice in web development tends to evolve, being able to translate one implementation to another is probably a very valuable skill.

Gareth Redfern
Gareth Redfern
36,217 Points

Fantastic video, we need more on this kind of thing Hampton Paulk :)

Matt Campbell
Matt Campbell
9,767 Points

AJAX is something I'd like to see. The rest you just learn as you work.

I have seen many ways to use AJAX some of them don't work on IE (this reason put me away from using AJAX) , I was wonder if the code displayed on the video is going to work efficiently across browsers and if this technique is ok to used on actual production.

Thank you.

Where as AJAX is really a concept we are using HTML5 and jQuery Ajax Post to make it happen. So as long as your browser can handle those, then you should be good to go Jose Labias

Michael Aguilera
Michael Aguilera
19,379 Points

This is awesome. i have been trying to wrap my head around AJAX and JSON and this begins to clarify it for me. Thanks.

that was really gr8 demo, wish we cud see a complex course on AJAX soon, since I get this question at every interview.

Awesome job! It was detailed and the pace was perfect.

Very nice video... I really needed this for a project I'm working on where I am implementing a 'click-to-see-more-entries' feature where it pulls users posts from a database and displays them without refreshing the page.