There are a couple of thing you'll need to make sure you're doing in order for this to work:
First, be sure you're using the Ajax Context Switch action helper: http://framework.zend.com/manual/en/zend.controller.actionhelpers.html#zend.controller.actionhelpers.contextswitch.ajaxcontext This makes it much easier to ensure that your ajax requests return the correct response. Basically, add this to your action controller: public function init() { $ajaxContext = $this->_helper->getHelper('AjaxContext'); $ajaxContext->addActionContext('adduser', 'json') ->initContext(); } In order to trigger the helper, you'll need to specify the format in your request. In jQuery, just append it to the form data: data: $('#frmAddUser').serialize()* + '&format=json'* At this point, your "success" callback should be firing. But in order for anything to be changed on the screen, you'll need to evaluate the response (which will be a JSON object) in your callback. AFAIK, there is nothing that happens magically to update the form on the screen. What you may want to do is set up your action method to assign the form errors to the view, which will appear in the JSON response. -- Hector On Fri, Nov 27, 2009 at 10:19 PM, Meroe <[email protected]> wrote: > Hey folks, > > > > I have what I hope is an easy issue to work around. I'm sure it is just my > lack of experience with ZF, but I'm learning as I go. > > > > > > I have a form set up that I created with Zend_Form that I would like to > submit via ajax (jquery) to avoid a page reload. I'm using layouts if that > matters. The issue is no matter what I do I can't see to get the validation > errors back to the form. If I look in firebug I can see the entire layout > loaded, but nothing changed in the form on the screen. If you need > anything further let me know and I'll include it. > > > > > > > > Here is my ajax: > > $(document).ready(function()*{* > > > > > > > > $("#frmAddUser").livequery('submit', function(eve)*{* > > > > eve.preventDefault(); > > > > $.post(*{* > > url: '/administration/adduser', > > type: 'POST', > > dataType: 'json', > > data: $('#frmAddUser').serialize(), > > success: function(response)*{* > > $('#error').html(response); > > alert(response); > > //alert('success'); // doesn't fire > > *}*, > > error: function(response)*{* > > alert(response); > > $('#error').html(response); > > *}* > > > > *}*); > > > > *}*); > > > > *}*); > > > > > > >
