All right, in the last lesson we looked at a jQuery GET request.
And in this lesson we're going to look at a jQuery post request.
And this is how we send data to a server and ask
it to update data or create some new data.
And this is really, really simple to,
it's just dot post and then some URL in here,
some data in here,
and a callback function with the data that's going to be returned.
That's literally all it is.
So your data should be an object of some kind.
So we get say, Hello world.
And that URL we need somewhere to post to.
And it's really, really hard to find a place to safely posting,
but I found one called HTTP bin.
So we do this as a URL,
HTTPS colon slash slash HTTP bin.org slash post.
And if we want to, we can put these on
separate lines just to make this look a little nicer.
And then we can say console.log post was complete with this data.
Console.log data post was complete with this data. And let's take a look.
This is all the data that we got back.
An HTTP, HTTP bin.org tends to give us all of our data back in the form of property here.
So it says hello world,
we can put anything in there though.
We get say, Instagram is equal to at coding dot for dot everybody.
Which if you want free coding tips and tricks definitely come check this out.
And form Instagram coding for everybody.
And so we know that that is actually working.
Now, if we want to make sure that it's not working,
we could always just try get.
We'll do dot get and will do it,
will create a get request to the slash post URL.
And you can see four or five,
that means not allowed.
You're not allowed to do that.
It has to be a post request.
So go ahead and give this a shot.
Use HTTP bin.org.
Don't forget you need HTTPS.
You might run into that error if it's coming from
an unsecure location to a secure location,
just make sure you have that S and there.
This is called your payload.
This is the data that you're going to be sending them.
And then you've got a callback function when it's done,
what are you doing with that data?
All we're doing here is we're doing console.log data.
Now this is really, really useful when you're creating a single page application or
progressive web app where you need someone to
register or log in and you don't want to take them to another page,
or you have an API endpoint,
or they have to log in through a different website, something like that.
You can send that data somewhere else for processing.
And that data can come back usually in the form of JSON.
And then JQuery can handle it very gracefully.
In the next lesson, let's go ahead and create
a random Star Wars character generator based
on pretty much everything we have done in this course.