NYCPHP Meetup

NYPHP.org

[nycphp-talk] Ajax 101: what to return from a POST

David Mintz vtbludgeon at gmail.com
Thu May 3 14:31:03 EDT 2007


Let's say you are displaying a form populated with data from a db table for
a user to edit, and you want to AJAXify(with Prototype). Your backend script
does the validation. Suppose they POST it and validation fails, what do you
do?

I have experimented with converting a PHP array of error messages (fieldName
=> errorMessage, etc) into JSON and sending that back, then doing DOM
scripting to stick the error messages into some DIVs. Kind of a lot of work,
but it's efficient in the sense that you only send data that the front end
needs.

The other option is to redraw the whole form with the error messages in the
DIVs and send back that chunk of HTML. Less efficient in that you are
sending back a bunch of bytes that are the same as what was there in the
first place, but more efficient in that you re-use more code, and do less
client-side acrobatics, than if you return a JSON data structure.

Am I being a byte-Nazi? Any thoughts?


-- 
David Mintz
http://davidmintz.org/

Just a spoonful of sugar helps the medicine go down
In the most delightful way.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20070503/d066709b/attachment.html>


More information about the talk mailing list