# ajax-form
The `ajax-form` is a custom element which wraps around a regular HTML `form` element, but submits the form data via AJAX. This allows the form to be submitted without a page reload, similar to using [HTMX](https://htmx.org/) and the `hx-swap` functionality.
```{note}
Make sure to [install `dj_angles` middleware](../installation.md#middleware) to use `is_post` and `is_ajax`. The `dj_angles` scripts must also be [included in the HTML template](../installation.md#scripts).
```
## Example
```python
# views.py
from django.shortcuts import render
from book.models import Book
def book_detail(request, book_id):
book = Book.objects.filter(id=book_id).first()
if request.is_post:
book.title = request.POST.get('title')
book.save()
if not request.is_ajax:
return redirect('book', id=book.id)
return render(request, 'book.html', {'book': book})
```
```html