Injecting JavaScript into HTML
Once we have finished this section, we will have a not-so-pretty but fully functional main view where we can add, edit, and delete to-do items using JavaScript to make calls to our Rust server. However, as you may recall, we did not add a delete
API endpoint. To inject JavaScript into our HTML, we will have to carry out the following steps:
- Create a
delete
item API endpoint. - Add a
JavaScript loading
function and replace the JavaScript tag in the HTML data with the loaded JavaScript data in the main item Rust view. - Add a JavaScript tag in the HTML file and IDs to the HTML components so that we can reference the components in our JavaScript.
- Build a
rendering
function for our to-do items in JavaScript and bind it to our HTML via IDs. - Build an
API call
function in JavaScript to talk to the backend. - Build the
get
,delete
,edit
, andcreate
functions in JavaScript for our buttons to use.
Let’s have a detailed look...