So now that we have the handler more or less in place, it's time to move on to the front end and just
see if we can get things working.
But before we do that, here in Handler's Dash API, where I create this variable rest for response,
I probably should put a little JSON tag here just to explicitly say that in JSON I want orders to be
called orders like that and say, OK, now let's go over to the sales page.
And of course, the only thing we're really concerned with right here is the JavaScript.
So the very first thing I'm going to do is right now, all of this JavaScript is just by itself at the
bottom of this.
And I'm going to wrap everything in here.
Before let token, I'm going to put that in a document added event listener, which is cleaner document
and event listener, and it will be on the condition the dome content loaded and will execute a function.
And I'll grab this part and cut it and backspace here to get rid of these blank lines and go right down
to the bottom of this right like that and paste that in there, OK, and move it over there.
That's cleaner.
It worked the other way, but this is actually much cleaner.
Now, just after my opening scripted ill-Defined two variables.
Two things that I know I'm going to have to pass to my statement as part of a JSON payload, and the
first one is the current page.
So I'll declare a variable at current page equal say one and I'll let page size, which is the other
thing I need to send along equal to three.
OK, so I only want to display three things per page and I want the current page to be equal to one.
OK, now these are outside of any functions or anything.
So these are available to everything inside the script.
Now, let's get out of here after we declare our token and our body, we get those values and we declare
a request options in between those wars.
Creator Jason Palit.
So I'll say let and I'll call it Nordea equal adjacent object or JavaScript object.
And it's going to have a page underscore size.
I'm looking for in the handler equal to page size and it's going to have current page current underscore
page be set to current page.
And of course those are hard coded values, but we'll fix that later on.
And then down here in the request options, I'll specify the body is Jason Stringer like.
Now, when we get down to this part, after we call all sales, what that's going to do now is give
us back a data object.
But inside of the data object, we're actually having our orders.
So we need to change them a little bit.
We'll say if data orders, if we have that value, if it's not set, then we want to go data orders
for each.
OK, so let's try this out and see what we get.
So go to my terminal.
I'll stop everything that's already stopped.
Start everything.
Go back to my Web browser and I'll go to the homepage and we are logged in, so that's good and I'll
go to admin, I should, first of all, open the JavaScript console so we'll see if there's any errors.
And I'll go to admin all sales.
And that's the only one we've been working on so far.
And we get two things back.
OK, perfect, so it actually seems to work now if we look at the response in the network.
And look at this.
And look at the response we get there.
We get back pages one page, sizes three, last pages one and Total Records is three, but I only see
two things showing up here.
So something doesn't seem quite right, but we're actually getting pretty close.
At least we successfully called our handler and we got some response back.
So we got item zero, item one, and that's it.
Even though the page size is three and we have three total records, we have some values back.
So why are we getting to.
Well, let's go back and look at our code.
And go to Handler's apartment and see what we actually passed it, I said to you need by buy right there.
So this call's online five thirty nine of my code.
It says get orders, patinated two.
So let's go look at Gettle orders patinated and see what that first argument is to.
I told it to have two per page, so that is correct.
For some reason I thought I'd say two to three but we said it to two.
So this seems to be working.
All right.
OK, so at least we have it connected.
We know that things are talking to each other as they should.
But what I'd really like to do is back here is I'd like to have some kind of forward and back button,
because right now we can only see the first page of data and there's no way I can get to the second
page.
So what I'm going to do is between this lecture and the next one is I'm going to go and put 10 or 15
orders in the database so that I can actually pazhani back and forth a little bit and we'll start working
on writing some some means of going back and forth between the pages of data.
And we'll get started on that in the next lecture.