All right, so in previous lecture, we discussed what Jason is and what its syntax looks like, as
we said, Jason is frequently used with Ajax.
So in this video, we're going to talk about what Ajax is.
And also we'll show you how Jason and Ajax can work together.
Again, I want to say that we are not going to use Ajax in our project, but because of that, it's
really closely related to Jason.
I decided to create a video regarding it as well.
So what is Ajax?
Ajax allows us to receive data from Web server and update Web page without reloading it.
And that's really a cool thing.
Ajax stands for asynchronous JavaScript XML.
In simple words, asynchronous can be defined in the following way.
When we request a server that in order to process it and get response, it needs some time during this
time until response is ready and you can do some other stuff.
So this process is called asynchronous process.
Actually, this is sort of a big topic and I'm not going to go deeper because I don't want to complicate
things and make you confused.
All right.
As is so in abbreviation X stands for X amount.
Actually, XML is like Jassam.
It was used to send and receive data, but it's kind and old, too.
Nowadays, in most cases, developers use JS.
You may ask then why do we use XML in abbreviation of Ajax?
The reason is that XML has been using for a long time.
It was really important to and so the name stayed in abbreviation.
But again today developers mostly use Jason.
OK, let's talk a little about what are the main differences between Jason and XML.
Jason does not use tax.
It's much shorter also to read and write.
Jason is quicker and it can use a race.
XML has to be passed by XML parser.
As for Jason, it can be passed just by using JavaScript metal, which you have already met in previous
lecture.
I mean, Jason Pass.
All right, so that's all about XML and the differences between JSON and XML formats.
Let's go to Brackett's and write some code in order to use Ajax when it server.
In this case, we're going to use light server of Brackett's.
So if you are using brackets, then it's fine.
But if you're using other text editor, for example, visual studio code or item that you need to install
extension called live server, or it might be called library mode and you will be OK to proceed this
video.
All right.
Let me explain what we are going to do.
Suppose that we have some database in which we have information about users and we need to get this
information.
In order to do that, we have to send request and then get data.
I'm not going to use a real database.
Let's just create new Jason file.
Call it users that Jason and incited.
Create an object.
Right, users.
And I'm going to assign to it a rate which will consist of two objects right here, name John.
And name, Nick.
All right, let's go to Scribbly Jaspal and delete this entire code.
So the first thing that we have to do in order to send request is to create a new instance of XML,
HTP request object.
Actually, this is a built in object in all modern Web browsers.
So let's go ahead and created the clear variable and call it XML HTP.
Which should be equal to new.
Ximo htp request.
As you can see, Ximo request is a function constructor, and we just created a new object using it.
Let's see, Castle, what this object looks like, right?
Castle looked like an answer to your XML htp.
So as you can see, we have here object, which has several methods and properties from where we will
use a couple of them.
All right.
Next, we need to use a method called Open, which we just saw a second ago.
This method specifies type of request.
Also, you are all I mean, for location and also it defines whether process is asynchronous or synchronous,
using true and false values.
So let's write XML, HTP and use method open.
So as a first argument, as we said, we need to specify type of request, it could be get or post get
is used to request data and posts is used to send data.
So we need to get that.
We need to specify far location.
In this case.
We need to write DOT.
Users thought, Jason.
Actually, you can armitt here because files are in the same directory, but I'm going to use it anyway.
And lastly, let's indicate that process is asynchronous.
For that, we need to use boolean value through.
All right, so in order to get a response, we need to use another method called OnLoad in which we
need to define function.
So let's write xml htp dot onload assigned to it function.
So now we need to use your statement in which we will check if everything is OK, in other words, if
response is ready for that, we have built in property cult status, which should be equal to two hundred.
It means, again, that response on our request is already besides two hundred.
It might be equal to for all three, which means that source is forbidden.
And also we could have four or four, which means that page is not found.
And actually I'm sure that you have seen four or four page not found lots of times in the Web.
All right.
Let's use each statement with the following condition, this DOT status.
Double equals to two hundred.
In this case, this key word refers to XML, htp object, so if this condition is true, it means that
response is already.
We are getting data.
This data is text and it's time to pass it using JSON that pass method.
I'm going to store past data into variable, so that's created.
Call it my data.
Which should be equal to Jason Dodd parts.
Now, we need to insert here as an argument, text of response, which we are getting and which should
be passed for that, we have to use another built in property called response text.
So.
Right, this DOT response text.
OK, that's it.
Finally, we need to send request to the server, and for that we have to use builtin method called
send the right XML htp dot set.
And let's see in council what we will receive, right, Coslett log.
My data.
So you can see that we have in council data, which we created in users that Jason file, and actually
it means that everything works fine.
So we sent request to the server, it prepared data for us and sent it to us back then we passed data
and got it in council.
That's the whole process.
All right.
So this is a little example of how we sent requests to the server and get data.
That's the basics of Ajax.
Again, it's sort of a big topic, but I think that this knowledge will be really helpful for you in
the future.
All right.
That was a mini section about basics of Jason and Ajax.
Finally, it's time to start building Chris application.
So let's move on to the next video.