Our AJAX Conventions – The AjaxContinuation


My team is coming out of the “infrastructure buildup” phase enough for me to take the time to blog. So, I’m going to do a write up of how we’re handling anything and everything AJAX and how it’s paying off really fast.

**Note:

** I want to make note of one thing here. As usual, I will be using FubuMVC as an example implementation of these concepts. However, these concepts are applicable in any web framework.

In this series of posts, I’m going to cover a few topics:

  1. The AjaxContinuation (this post)
  2. Clientside Continuations
  3. Request Correlation
  4. Validation

The Ajax Continuation

Like every “convention”, you have to start with some commonality and standardize a few things. For our usage, we chose to use the standard AjaxContinuation in FubuMVC. Here’s a JSON representation:

Nothing too fancy here but this is just the baseline. The point is that while there may be additional properties specified on a particular instance, the properties above will always be there.

Let’s run through each of the properties:

success

Type: bool

Flag indicating whether the request was successful.

refresh

Type: bool

Flag indicating whether the page should be refreshed.

message

Type: string

Server generated message describing the result of the request (or anything else you want to use it for)

errors

Type: Array

An array of AjaxError objects ( { category: ‘’, field: ‘’, message: ‘’ })

AjaxContinuation and FubuMVC

As I said before, this is a first-class citizen in FubuMVC. There are default conventions provided for you. All you need to do is return an AjaxContinuation from one of your actions and we take care of the rest.

But just for sake of clarity, here’s an example:

Don’t worry, I give a lot more information in the next few posts.

Until next time.

fubu new project