Ajax message protocol

0 views
Skip to first unread message

Juergen Schreck

unread,
Sep 14, 2006, 10:04:35 PM9/14/06
to MochiKit
Fairly new to AJAX and this Async stuff...

The errback callback is only invoked upon HTTP header status codes I
assume.

So the question is, what is a good model to communicate application
level messages and errors?

E.g. I'm doing a POST to insert a database record. Assume this fails
on the and I want to have my client-side to handle this gracefully.
Same would go for server side validation of other sorts. What's a
good way to send this meta-data back which is easy to use by the client?

Right now, I'm just returning html snippets. Not doing anything with
JSON or XML yet.

In one case, I'm returning multiple snippets separated by a 'well-
known' string. The client 'splits' the responseText and put's each
snippet part where it belongs. I suppose, one could add a simple
protocol header ahead of the snippets and interpret that upon success
to handle such situations.

But I'm always looking for good and reusable solutions, especially
within MochiKit. So if anyone with more experience than me can make
some suggestions here, I'd really appreciate it.

Thanks,
Juergen


Bob Ippolito

unread,
Sep 14, 2006, 10:10:18 PM9/14/06
to Juergen Schreck, MochiKit
On 9/14/06, Juergen Schreck <juergen...@innernine.com> wrote:
>
> Fairly new to AJAX and this Async stuff...
>
> The errback callback is only invoked upon HTTP header status codes I
> assume.
>
> So the question is, what is a good model to communicate application
> level messages and errors?
>
> E.g. I'm doing a POST to insert a database record. Assume this fails
> on the and I want to have my client-side to handle this gracefully.
> Same would go for server side validation of other sorts. What's a
> good way to send this meta-data back which is easy to use by the client?

You can use an error status code and you'll get the error object in
the errback. You can still get at the XMLHttpRequest from that error
object.

http://mochikit.com/doc/html/MochiKit/Async.html#fn-xmlhttprequesterror

-bob

Reply all
Reply to author
Forward
0 new messages