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

JavaScript

Clarity on sending data through AJAX

Hi all,

let url = 'someurl.php';
let data = {
      someonesName : 'name'
      password: 'paaaasssword'
};
let callback = (response) => {
//codeee
};
$.get(url, data, callback);

What I understand here is we request from the url, send data for an unbeknown reason? then once the server responds follow through with our callback. I think we're checking if the name and password is in the db by sending a request to the server? If so, then is the above code (the data param) same as the argument passed into .send(//argument);?

is that ^ the same as:

let xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
    if (xhr.readyState===4) {
    }
};

xhr.open('somelink.php');
xhr.send({
      someonesName : 'name'
      password : 'paaaassword'
});

??? i.e. is data param in $.get(); same as the argument in send();

if it is then that helps massively! Any and all help is greatly appreciated, I feel like Tree House have done a pretty underwhelming job with their AJAX videos everything until now has been extremely clear.

Thanks again, Ale8k.