From the course: HTMX Essential Training

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Processing JSON response data

Processing JSON response data - HTMX Tutorial

From the course: HTMX Essential Training

Processing JSON response data

- [Instructor] Now that we're able to handle this post request using HTMX, let's go ahead and adjust this so that we can handle the response data a little bit more dynamically. So the first thing that we'll do here is we will scroll down in our Server.JS file where we are returning all of this parsed data. And instead of returning the data here I want to return, a message, and the message should read Hello parsedData.name. Okay, so once I've done that, let's add an exclamation point for excitement's sake. Then we're going to go ahead and adjust our HTML. So we need to use hx-swap. hx-swap is going to replace the contents of the response div with our server response. So that'll look like this. We'll say hx-swap in our HTML. Then we will use the target, the submit, and the slash route for posting just the same. And then, what we can do is run it. So we will make sure that we're navigated to the right folder. Let's move this up a little bit, then we're going to run node server. So here's…

Contents