AJAX

7 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$99.99
List Price:  $139.99
You save:  $40
€95.97
List Price:  €134.37
You save:  €38.39
£79.79
List Price:  £111.71
You save:  £31.92
CA$140.31
List Price:  CA$196.44
You save:  CA$56.13
A$153.75
List Price:  A$215.26
You save:  A$61.51
S$134.64
List Price:  S$188.51
You save:  S$53.86
HK$778.36
List Price:  HK$1,089.74
You save:  HK$311.37
CHF 89.34
List Price:  CHF 125.09
You save:  CHF 35.74
NOK kr1,107.14
List Price:  NOK kr1,550.05
You save:  NOK kr442.90
DKK kr715.75
List Price:  DKK kr1,002.09
You save:  DKK kr286.33
NZ$171.37
List Price:  NZ$239.93
You save:  NZ$68.55
د.إ367.26
List Price:  د.إ514.18
You save:  د.إ146.92
৳11,945.63
List Price:  ৳16,724.36
You save:  ৳4,778.73
₹8,442.99
List Price:  ₹11,820.52
You save:  ₹3,377.53
RM446.75
List Price:  RM625.47
You save:  RM178.72
₦169,271.38
List Price:  ₦236,986.70
You save:  ₦67,715.32
₨27,777.22
List Price:  ₨38,889.22
You save:  ₨11,112
฿3,446.26
List Price:  ฿4,824.91
You save:  ฿1,378.64
₺3,454.90
List Price:  ₺4,837
You save:  ₺1,382.10
B$580.04
List Price:  B$812.08
You save:  B$232.04
R1,815.38
List Price:  R2,541.61
You save:  R726.22
Лв187.66
List Price:  Лв262.73
You save:  Лв75.07
₩140,436.95
List Price:  ₩196,617.35
You save:  ₩56,180.40
₪371.46
List Price:  ₪520.07
You save:  ₪148.60
₱5,893.31
List Price:  ₱8,250.87
You save:  ₱2,357.56
¥15,475.45
List Price:  ¥21,666.25
You save:  ¥6,190.80
MX$2,042.64
List Price:  MX$2,859.78
You save:  MX$817.14
QR364.56
List Price:  QR510.41
You save:  QR145.84
P1,367.06
List Price:  P1,913.94
You save:  P546.88
KSh12,945.58
List Price:  KSh18,124.33
You save:  KSh5,178.75
E£4,964.52
List Price:  E£6,950.52
You save:  E£1,986
ብር12,237.67
List Price:  ብር17,133.23
You save:  ብር4,895.55
Kz91,290.87
List Price:  Kz127,810.87
You save:  Kz36,520
CLP$97,782.75
List Price:  CLP$136,899.76
You save:  CLP$39,117.01
CN¥724.22
List Price:  CN¥1,013.94
You save:  CN¥289.72
RD$6,024.63
List Price:  RD$8,434.73
You save:  RD$2,410.09
DA13,426.15
List Price:  DA18,797.15
You save:  DA5,371
FJ$227.57
List Price:  FJ$318.61
You save:  FJ$91.03
Q771.64
List Price:  Q1,080.33
You save:  Q308.69
GY$20,913.50
List Price:  GY$29,279.73
You save:  GY$8,366.23
ISK kr13,962.80
List Price:  ISK kr19,548.48
You save:  ISK kr5,585.67
DH1,005.63
List Price:  DH1,407.93
You save:  DH402.29
L1,821.98
List Price:  L2,550.85
You save:  L728.86
ден5,904.20
List Price:  ден8,266.12
You save:  ден2,361.91
MOP$801.48
List Price:  MOP$1,122.11
You save:  MOP$320.62
N$1,812.81
List Price:  N$2,538.01
You save:  N$725.20
C$3,678.31
List Price:  C$5,149.78
You save:  C$1,471.47
रु13,500.25
List Price:  रु18,900.90
You save:  रु5,400.64
S/379.05
List Price:  S/530.69
You save:  S/151.63
K402.47
List Price:  K563.48
You save:  K161
SAR375.40
List Price:  SAR525.58
You save:  SAR150.17
ZK2,764.29
List Price:  ZK3,870.12
You save:  ZK1,105.82
L477.77
List Price:  L668.90
You save:  L191.12
Kč2,432.37
List Price:  Kč3,405.42
You save:  Kč973.04
Ft39,496.05
List Price:  Ft55,296.05
You save:  Ft15,800
SEK kr1,103.50
List Price:  SEK kr1,544.95
You save:  SEK kr441.44
ARS$100,363.46
List Price:  ARS$140,512.86
You save:  ARS$40,149.40
Bs690.75
List Price:  Bs967.07
You save:  Bs276.32
COP$438,931.09
List Price:  COP$614,521.09
You save:  COP$175,589.99
₡50,918.63
List Price:  ₡71,288.12
You save:  ₡20,369.49
L2,526.16
List Price:  L3,536.73
You save:  L1,010.56
₲780,388.98
List Price:  ₲1,092,575.79
You save:  ₲312,186.81
$U4,261.82
List Price:  $U5,966.72
You save:  $U1,704.90
zł416.31
List Price:  zł582.85
You save:  zł166.54
Already have an account? Log In

Transcript

Hello, in this JavaScript video, I am going to cover Ajax. So Ajax is essentially like a developer's dream allows you to do stuff like update the website or your web page without even reloading the page. So get content, it, you can request data from the server after the pay to the Ruby node ID. You can receive data from a page after it's been loaded. And you can even send data back to the server in the background without reloading your page. So this is fantastic if you're trying to create a website, somewhere suffering going on seamlessly loading data, sending back data.

Again, you know, not all data that goes back and forth needs Ajax or will even be enhanced with Ajax in any positive way. But there are many, many scenarios. One thing to bear in mind may have already noticed if you follow the other videos in this series, is that the the link is a bit different. That's because I'm using a server, local server and firewall Whatever it is, but you're generally need to serve or do and you'll come across errors in your browser to be able to use Ajax. So if you're testing locally, or recommend just setting up a survey, I would recommend x amp that x A MPP. And that's cross platform.

There are other options as well, such as node and some building servers into Unix like Unix like Unix like based systems, but example in my recommended one, I'll put a link to that as well. Okay, and yeah, that's it. If you're online, then you're home. If you want to be in a service, that is alright anyway. So what we're actually going to do to create a create a button on our world is got this little button button right here, and I'm going to say on click on click, we are going to call song function, and this is gonna be called load data. That's something that we are going to be making.

We'll make that in here. So function load data. That's my footwork, it's always good to just quickly confirm, to hate you. So when I click it, we get to see the page isn't window there at all. And that's a thank you what we're going to be able to do boom, going to be able to get content. And what we're actually going to do is I've got a text file right here that just says, Hello, everybody.

I'm Dr. Nick, cofounder, TC, we're going to load the data from there. This could be well, this is on the server. So it doesn't matter what it is. This allows you to get that content number awesome thing is you could use Ajax to communicate with some code a code file and load data from a database. So running code execution in on the server. Okay, so to actually do Ajax in JavaScript was going to pick a variable called x HTTP.

And we need to create a new XML HTTP request. I don't think I told you or explain what Ajax stands for by direct sorry. It just stands for Asynchronous JavaScript and XML. It's not a programming language at all. It's just basically a feature. It uses a combination of browser built in HTTP requests to get data from a server and the JavaScript and the HTML Dom to display and use the data.

And Ajax is sort of a you know, misleading name because they suggest that, you know, XML is always used in it. Yes, Ajax applications could use XML to transport data. back from the server, but you can equally just transported via plain text or JSON as well. So it could just be called Ajax. For a a judge Agus, I guess they don't sound as good as Ajax and I'm pretty sure Ajax is a is an old Greek word. I think it is a Greek or Latin word.

I'm pretty sure it is. I don't know what it means. Have a look at that afterwards. Okay, so what we need to do is take some TP on ready. Ready? Ready, we are going to call this function and put some code on here.

We're going to say if this dot ready state really equals four. So if the status equal to four and 200 that means everything in a okay and we can Continue the two students that we want to discuss data equals know how you have you know, different status 504 and a five or something like error state see this is an okay status. And what we are going to say is in here, this is where we would print something that we've loaded, so we would do this, we could do one one, we could put it in some HTML, we could print it out into the console literally printed out onto onto a father matter the longest, I'm going to put this dot response text, which is the return from the false in this case, just be the text content, the file content, and, but we here, we need to actually open the file, we're gonna open it using a get request Get.

And so the file location, which is just in the same location as my index and the custom j s file, if it isn't, then you need to put like folder path as well. Like so. Wrong. Now you just do x HTTP. So what is happening is we are opening this fall we're sending it. And this is just saying when the x HTTP is saying it's ready.

So solid ready status change, then, you know, do some code. So this doesn't necessarily come afterwards. It just means once the state changes, then execute this function and that could be when ever to run the application. So if I run it, now I click that, as you can see, we are getting that content and the page is not reloading. By the favicon, not, you know, refreshing, and that's good. So it is this content from this file right here.

So that's it for Ajax in JavaScript. What I recommend is using a framework on top of JavaScript such as the, you know, world popular jQuery, and jQuery has really awesome built in methods to enhance the experience of using jQuery Ajax in your website. That's it. If you have any questions, feel free to drop me a message and I look forward to seeing you in the next video.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.