Using GET requests in JavaScript
Let there be some object on a server:
server.jslet obj = {1: 'a', 2: 'b', 3: 'c'};
export default function({get}) {
}
Let's make three links that send GET parameters to the server:
public/index.html<a href="/handler/?key=1">1</a>
<a href="/handler/?key=2">2</a>
<a href="/handler/?key=3">3</a>
Now we will correct the server code so that following the link shows the corresponding object element:
server.jsexport default {
'/handler/': function({get}) {
let obj = {1: 'a', 2: 'b', 3: 'c'};
return obj[get.key];
}
}
Задание 1
Let a server have an array with users:
server.jslet arr = [
'user1', 'user2', 'user3'
];
Make links that show relevant users in the browser.
Задание 2
Modify the previous task so that if there is no element in the array with the passed key, an error is sent to the browser.