Thanks for your reply: On 14 Feb 2009, at 14:19, Veikko Mäkinen wrote: > Michal Charemza wrote: >> >> - So would I need to "route" based on the X-Requested-With header, to >> a new action: say 'PostCommentsAjax' action? How would I do this? > > Almost correct - you'd use a route to alter the output type, not > action. > You can see how this is done in the sample app: > > Route (line 17): > http://trac.agavi.org/browser/branches/1.0/samples/app/config/routing.xml > > Output type (json) > http://trac.agavi.org/browser/branches/1.0/samples/app/config/output_types.xml Is it better to depend on HTTP_ACCEPT or X-Requested-With? I guess if JSON is to be the output, then HTTP_ACCEPT...?
>> - Should this PostCommentsAjax action be a subclass of >> PostCommentsAction? I would like to avoid copy/pasting the code from >> PostCommentsAction. >> > > Actions should never know anything about the output type. Just use the > same PostCommentsAction as for HTML output type. The only thing you > need > to add is executeJson() in your view. Remember, only the View part in > MVC is different here. Ah... thanks. >> good idea to actually return a JSON object, with the html as one of >> the values, as I might want other parameters passed back, like >> "success:true" or something. > > I'd return JSON telling the result code (e.g. "success" or "error") > and > validation errors (fields and error messages, you can easily get them > from the validation manager). You can then easily highlight erroneous > fields and their labels and inject error messages next to the fields > and/or form. For the errors of the form, I think I agree. However, if there are no errors, I would like to return the whole comment as HTML to be injected into the page. If HTML isn't returned within the JSON, then the front-end javascript would have to know about the html-structure of the comments (which I would prefer to avoid). So the executeJson() method would need to access both a template for JSON, and the template used for comments. How would I go about do this? I'm guessing it's something to do with layers, but unfortunately I've not got to grips with quite how layers work yet... Sorry if these are basic questions... Without a manual I feel like I'm flying blind... Michal. _______________________________________________ users mailing list [email protected] http://lists.agavi.org/mailman/listinfo/users
