Alright, let's look at ajax and some data with a little bit of a call back.
Now we need a place to get data from.
And one of my personal favorites is swampy dot dev is as a Star Wars API.
And if you go to swap e dot dev slash api slash people slash one,
you're going to see this information about Luke Skywalker.
And so we can actually go there swapping dot.gov slash API slash people slash one.
And we see all this information.
But Luke Skywalker, Now this is the URL.
We want this an API endpoint.
We want to be able to get this information,
this JSON information, and access it quite easily.
So what we can do here is if I just move this up and actually no,
let's undock this is we have access to jQuery in here with a dollar sign.
You can see that we can use dot get and then that URL.
Now if we do just that,
we're going to see that it's just a regular Ajax request.
But if I clear that out and give it a callback function,
we know about callbacks, we know about functions.
Let's do console dot log the data.
And we're gonna see that this is the Ajax request here and this is our data.
And so we're doing a get request here.
We're simply asking for data.
And so by using dollar sign dot get,
there's no selector here because we're not selecting anything.
And because there's no selector,
we don't have a sector, it's just dollar sign dot get.
And so now we have all this information loaded on our page
or in our console at least that was available over here,
named Luke Skywalker height 172 mass 77.
172, mass 77, name Luke Skywalker.
It's all the same information.
And so that's how we do a simple ajax request in jQuery.
Know woods wild about that is this is so incredibly simple.
We can do dot get.
And I've just pasted that URL in there, the data.
And then we can console dot log data name.
That was what we're looking for, right name.
So let's go ahead and save this.
And let's just refresh this page.
And it goes and gets it.
It says Luke Skywalker,
we could get his height.
We could get his weight if we wanted to.
Luke Skywalker 172.
Wait, wasn't in there.
It's called mass.
That's why his mass is 77.
And so now we don't have to worry about like a fetch API requests.
We don't have to worry about taking that data in and basically
parsing the JSON and turning it into a JSON or JavaScript Object.
We don't have to worry about any of that because jQuery is
doing all of that behind the scenes and it does it with
a single line of code with
the dot get function that you're going to need to know this for your final project.
So I highly recommend that you give this a shot to try it out.