Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9523d5c

Browse files
committedJun 21, 2024
advance portion start ...
1 parent dcf62ea commit 9523d5c

File tree

2 files changed

+153
-0
lines changed

2 files changed

+153
-0
lines changed
 

‎09_advance_One/index.html

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>XMLHTTPREQUEST</title>
7+
</head>
8+
<style>
9+
body {
10+
background-color: #212121;
11+
color: #fff;
12+
}
13+
</style>
14+
<body>
15+
<h1>ajax programing</h1>
16+
</body>
17+
<script>
18+
//Notes
19+
// console and many api are not part of core js
20+
//document are also not part of core js
21+
// console.log is a debbuging tool of browser develpor tool..
22+
//yh console.log browser ka run time inject krta he .
23+
//v8 engine is js engine .. which is written in c++
24+
//in v8 api there is communication between js and c++
25+
// d8 folder must see line 104
26+
// console.log(XMLDocument);
27+
// console.log(XMLHttpRequest);
28+
const requestUrl = "https://api.github.com/users/hiteshchoudhary";
29+
const xhr = new XMLHttpRequest();
30+
xhr.open("GET", requestUrl);
31+
xhr.onreadystatechange = function () {
32+
console.log(xhr.readyState);
33+
if (xhr.readyState === 4) {
34+
const data = JSON.parse(this.responseText);
35+
console.log(typeof data); // string.. after json it will json
36+
console.log(data.followers);
37+
}
38+
};
39+
40+
// console.log("HERE");
41+
xhr.send();
42+
</script>
43+
</html>

‎09_advance_One/promises.js

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// console.log("is js working");
2+
3+
// fetch("https://something.com").then().catch().finally(); //Basic syntax
4+
5+
// const promiseOne = new Promise(function (resolve, reject) {
6+
// //Do an async task
7+
// //DB calls ..conntect..send..recive ..inject CryptoGraphy Network Call
8+
9+
// setTimeout(function () {
10+
// console.log("async task is completed ");
11+
// resolve();
12+
// }, 2000);
13+
// });
14+
// promiseOne.then(function () {
15+
// console.log("process is consumed");
16+
// });
17+
18+
// new Promise(function (resolve, reject) {
19+
// setTimeout(function () {
20+
// console.log("async task 2");
21+
// resolve();
22+
// }, 1000);
23+
// }).then(function () {
24+
// console.log("async task 2 is resolved");
25+
// });
26+
27+
// const promiseThree = new Promise(function (resolve, reject) {
28+
// setTimeout(function () {
29+
// resolve({
30+
// name: "waseem akram",
31+
// gmail: "malikwaseemshzad@gmail.com",
32+
// }); // in resolve parameter we can pass object ,fucntion and array ....
33+
// }, 1000);
34+
// });
35+
36+
// promiseThree.then(function (user) {
37+
// // console.log(user);
38+
// // console.log(user.gmail);
39+
// });
40+
41+
// const promiseFour = new Promise(function (resolve, reject) {
42+
// setTimeout(function () {
43+
// let error = false;
44+
// if (!error) {
45+
// resolve({ username: "wcoder547", password: "123" });
46+
// }
47+
// if (error) {
48+
// reject("Error,Something Went Wrong!!");
49+
// }
50+
// }, 1000);
51+
// });
52+
53+
// promiseFour
54+
// .then(function (user) {
55+
// console.log(user);
56+
// return user.username;
57+
// })
58+
// .then((username) => {
59+
// console.log(username);
60+
// })
61+
// .catch(function (error) {
62+
// console.log(error);
63+
// })
64+
// .finally(() => console.log("The promise is resolved or rejected"));
65+
66+
// const promiseFive = new Promise(function (resolve, reject) {
67+
// setTimeout(function () {
68+
// let error = true;
69+
// if (!error) {
70+
// resolve({ username: "wcoder547", password: "123" });
71+
// }
72+
// if (error) {
73+
// reject("Error,Something Went Wrong!!");
74+
// }
75+
// }, 1000);
76+
// });
77+
78+
// async function consumePromiseFive() {
79+
// try {
80+
// const response = await promiseFive;
81+
// console.log(response);
82+
// } catch (error) {
83+
// console.log(error);
84+
// }
85+
// }
86+
87+
// consumePromiseFive();
88+
89+
// async function getAllUsers() {
90+
// try {
91+
// const response = await fetch("https://jsonplaceholder.typicode.com/users");
92+
93+
// const data = await response.json();
94+
// console.log(data);
95+
// } catch (error) {
96+
// console.log(error);
97+
// }
98+
// }
99+
//getAllUsers();
100+
101+
fetch("https://jsonplaceholder.typicode.com/users")
102+
.then(function (response) {
103+
return response.json();
104+
})
105+
.then(function (data) {
106+
console.log(data);
107+
})
108+
.catch(function (error) {
109+
console.log(error);
110+
});

0 commit comments

Comments
 (0)
Please sign in to comment.