Basic Authentication - Using Jquery

11 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$49.99
List Price:  $69.99
You save:  $20
€46.41
List Price:  €64.98
You save:  €18.57
£39.74
List Price:  £55.64
You save:  £15.89
CA$68.36
List Price:  CA$95.72
You save:  CA$27.35
A$75.43
List Price:  A$105.61
You save:  A$30.18
S$67.50
List Price:  S$94.51
You save:  S$27
HK$390.66
List Price:  HK$546.96
You save:  HK$156.29
CHF 45.28
List Price:  CHF 63.39
You save:  CHF 18.11
NOK kr542.32
List Price:  NOK kr759.29
You save:  NOK kr216.97
DKK kr346.21
List Price:  DKK kr484.72
You save:  DKK kr138.51
NZ$83.04
List Price:  NZ$116.27
You save:  NZ$33.22
د.إ183.60
List Price:  د.إ257.06
You save:  د.إ73.45
৳5,477.48
List Price:  ৳7,668.91
You save:  ৳2,191.43
₹4,173.46
List Price:  ₹5,843.17
You save:  ₹1,669.71
RM236.90
List Price:  RM331.68
You save:  RM94.78
₦61,737.65
List Price:  ₦86,437.65
You save:  ₦24,700
₨13,884.75
List Price:  ₨19,439.77
You save:  ₨5,555.01
฿1,836.53
List Price:  ฿2,571.29
You save:  ฿734.76
₺1,613.79
List Price:  ₺2,259.44
You save:  ₺645.64
B$253.58
List Price:  B$355.04
You save:  B$101.45
R921.65
List Price:  R1,290.39
You save:  R368.73
Лв90.79
List Price:  Лв127.12
You save:  Лв36.32
₩67,757.86
List Price:  ₩94,866.43
You save:  ₩27,108.56
₪187.05
List Price:  ₪261.89
You save:  ₪74.83
₱2,856.96
List Price:  ₱3,999.98
You save:  ₱1,143.01
¥7,687.37
List Price:  ¥10,762.93
You save:  ¥3,075.56
MX$846.40
List Price:  MX$1,185.03
You save:  MX$338.62
QR182.04
List Price:  QR254.87
You save:  QR72.83
P679.94
List Price:  P951.97
You save:  P272.03
KSh6,711.15
List Price:  KSh9,396.15
You save:  KSh2,685
E£2,396.98
List Price:  E£3,355.96
You save:  E£958.98
ብር2,864.89
List Price:  ብር4,011.08
You save:  ብር1,146.18
Kz41,759.31
List Price:  Kz58,466.37
You save:  Kz16,707.06
CLP$47,049.08
List Price:  CLP$65,872.48
You save:  CLP$18,823.40
CN¥353.90
List Price:  CN¥495.49
You save:  CN¥141.59
RD$2,900.17
List Price:  RD$4,060.47
You save:  RD$1,160.30
DA6,724.18
List Price:  DA9,414.39
You save:  DA2,690.21
FJ$112.18
List Price:  FJ$157.07
You save:  FJ$44.88
Q387.94
List Price:  Q543.15
You save:  Q155.20
GY$10,441.17
List Price:  GY$14,618.48
You save:  GY$4,177.30
ISK kr6,976.60
List Price:  ISK kr9,767.80
You save:  ISK kr2,791.20
DH503.40
List Price:  DH704.80
You save:  DH201.40
L884.08
List Price:  L1,237.78
You save:  L353.70
ден2,857.75
List Price:  ден4,001.09
You save:  ден1,143.33
MOP$401.71
List Price:  MOP$562.43
You save:  MOP$160.71
N$923.86
List Price:  N$1,293.49
You save:  N$369.62
C$1,837.28
List Price:  C$2,572.34
You save:  C$735.06
रु6,663.84
List Price:  रु9,329.91
You save:  रु2,666.07
S/186.31
List Price:  S/260.85
You save:  S/74.53
K192.92
List Price:  K270.11
You save:  K77.18
SAR187.49
List Price:  SAR262.50
You save:  SAR75.01
ZK1,346.25
List Price:  ZK1,884.87
You save:  ZK538.61
L230.87
List Price:  L323.24
You save:  L92.36
Kč1,161.41
List Price:  Kč1,626.08
You save:  Kč464.66
Ft18,082.13
List Price:  Ft25,316.43
You save:  Ft7,234.30
SEK kr541.20
List Price:  SEK kr757.73
You save:  SEK kr216.52
ARS$43,928.30
List Price:  ARS$61,503.14
You save:  ARS$17,574.83
Bs345.62
List Price:  Bs483.90
You save:  Bs138.27
COP$194,235.29
List Price:  COP$271,944.94
You save:  COP$77,709.65
₡25,508.30
List Price:  ₡35,713.67
You save:  ₡10,205.36
L1,232.91
List Price:  L1,726.17
You save:  L493.26
₲373,633.39
List Price:  ₲523,116.65
You save:  ₲149,483.25
$U1,909.79
List Price:  $U2,673.86
You save:  $U764.07
zł200.70
List Price:  zł281
You save:  zł80.29
Already have an account? Log In

Transcript

Hello guys, welcome to the 25th session of the as we don't have a VBA to in a previous lesson we successfully created the basic auth attribute using which we can provide the basic authorization for the our VP, we can use that attribute at the controller level as well as the accent level. In this lesson we are going to use the jQuery Ajax request for basic authorization policies let's switch to visitor to add a new page. So data in this page, we are going to design a form which contain the toolboxes in which the user can insert the username and a password and click on the button which will retrieve the list of the employee as per the logged in user for this mini tour idea and User Name colon input type equals to text and br for a newline by swore input type equal to the password.

Again we are using Gambia for the break and button with the ID btn. So login and so data and one deal with that content the word result with the ID reserved We also need to assign the ID to the both of the input. Let's use the password for the password and the username for the text. From the script folder, we need to include the jQuery reference. Create a script tag to type JavaScript. Within that one the document is ready.

We need to call that anonymous function when the our button that is has btn so click Ready to perform below function we need to go to the user name. For that we're going to write the dollar. Select a name that is user name, username. Oh, well and same for the password for password to use the class war now we need to send the AJAX refresh. For that we need to write dollar Ajax and pass the request data URL all on. Let's copy from the postman and paste within the single core right there.

At DDP colon, forward slash forward slash is at the end specify the type of request that is gate and the data type of response that is JSON and headers that will contain the our authorizes in detail or Thor ization. We are going to use the basic authorization therefore we need to write the basic space and append do a username and a password in the form of the base 64. Therefore, we need to use B to A function and do write the user name hi append the colon sign with the password and create the error handler in which we as simply an idea or message indeed there is a dot html and encounter all right alright to create a success method success function within the function we got the data. In this example I'm going to display the ID name and the HR department follows each employee.

Therefore, we need to use The aware formated data equal to empty string and for each of data we will pass we will get the index and the value and for which we need to conquer the our formatted data. Value dot height hiedi pipe sign value dot name. Again pipe sign and value dot department right do a semicolon at the end side To the result and we also need to create the complete handle in which we are receiving the objects or object from which we need to check what our status is 200 cash transfer okay? Even though our assets our status is not okay that is a 200 then we need to show the Sgt score as well as the citizen description to the war. What What is her do x x HR dot two status plus x HR dot status text. That's it.

Let's run the solution. Let's click on the login and soil data. We are receiving the error encountered because of we are not enter the username and password. This was the wrong message. You should have this we need to receive the 401 unauthorized user message. For that we need to see the console tab, open the Inspect Element click on the console That is an error that x actually is not defined on the line number 32 lets me show is the studio here instead of using the accessory we need to write the etc.

There was a typo and reload the our page. Now we're going to click on login, we can see that we are received the 401 unauthorized error. And right the tester tester. Then we are Oops, I'm forgot to ask him those all element for that. We need to write the dollar sign open the curly braces mosy dollar curly braces, close it, dollar open. Close the curly braces, as well as we need a VR for the brain.

And reload the page. Right The teacher has a password and click on login. Here we can see that it written the foreign five employee, that is Priyanka and both of them artista. Let's write the wrong username. We are at the unauthorized era. And now the idea they will offer they will offer and we will review the L three o employed war the developer.

For sending the basic authentication using the jQuery, we need to use the AJAX request in which we need to use the authorization header in which we need to write the basic space. Our username and password are separated by the colon in the form of the basics. Before that we need to use the A B to A function And thanks for watching. Have a nice day.

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.