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

General Discussion

ajax with jquery

hello ! I am new here ...Is there something on treehouse about ajax with jquery? Thank you

4 Answers

Hey there,

Apperantly there is not ! However it is not that difficult:

Here is the jQuery documentation: https://api.jquery.com/jQuery.ajax/

$.ajax({
  type: "POST", // The type of submitting your data , POST will probably be the one you'll need
  url: "some.php", // The URL to the file you are trying to get output from
  data: { name: "John", location: "Boston" } // The data you want to submit with it
})
  .done(function( msg ) { // This function will be executed when the status of the result is code 200.
    alert( "Data Saved: " + msg ); // Here is pretty clear what happens, also 'msg' is the result of the "some.php" file with the supplied data.
  });

To make this answer complete: the some.php file would contain something like this:

if(isset($_POST['name'] && $_POST['location'])){
$name = $_POST['name'];
$location = $_POST['location'];
if($name == 'John' && $location == 'Boston'){ // Here you probably do some DataBase thingie
 echo 'Yay you are John from Boston';
} else {
 echo 'Sorry you are not John from Boston';
}
}

Good luck !

Dave McFarland
STAFF
Dave McFarland
Treehouse Teacher

Hi cristian bolea

An AJAX course is in the works! I'll be teaching it and it will cover jQuery with AJAX (as well as plain old JavaScript and AJAX). Look for it in a month.

Love the tutorials and setup of the courses you have here. I LOVE LOVE LOVE that you guys created the "tracks" as now I know a route to take to build a website with Ruby on Rails. I've spent so much time researching on the path to take and so you guys did it for me.Not only that, you guys are up to date and you don't have a billion courses to choose from; just the new and good stuff to know. Sometimes too many options is worse than not enough. These 2 points tipped me into signing up with you guys. Dave, hurry the hell up with the AJAX course. I'm excited to learn about it.

Dave McFarland
Dave McFarland
Treehouse Teacher

Hi ramonakim

Glad you're enjoying our classes and the way we have organized them...and I'm hurrying!!!!

Dave McFarland Thank you :)