Let's create scripts.js as shown in the following. The JavaScript function is interacting with the endpoints and stitching together the overall user experience of the Pictorial Translator. Let's have a look at the following code:
- First, define serverUrl as the address of chalice local.
- We will also define a new HttpError to handle the exceptions that might occur during the HTTP requests.
- Add this JavaScript class at the end of the scripts.js file:
"use strict";const serverUrl = "http://127.0.0.1:8000";...class HttpError extends Error { constructor(response) { super(`${response.status} for ${response.url}`); this.name = "HttpError"; this.response = response; }}
- Next, we will define four functions in scripts.js:
- uploadImage() ...