Quake3World.com
https://www.quake3world.com/forum/

Zend/jQuery interaction
https://www.quake3world.com/forum/viewtopic.php?f=16&t=41930
Page 1 of 1

Author:  Kaz [ 11-04-2009 11:58 AM ]
Post subject:  Zend/jQuery interaction

So, I'm building a site for work, and I have a form with a submit button. The input fields of the form correspond to fields in the database, and I'd like for the button to make an AJAX request using jQuery to save the data, then do nothing. However it goes ahead and renders a blank page with whatever I echo...

Here is relevant code:

Code:
In IndexController:

    public function init()
    {
         //other stuff
   $ajaxContext = $this->_helper->getHelper('AjaxContext');
        $ajaxContext->addActionContext('save', 'html')
                          ->initContext();
    }

    public function saveAction()
    {
        //Shouldn't need to do this?
       $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);

   $fname = $this->getRequest()->getParam('fname');
   $this->user->setFname($fname);
   $this->user->save();

   $response = new Zend_Controller_Response_Http();
   $this->setResponse($response);
        
        echo 'fcku';
    }


Code:
Javascript:
function saveData(event)
{
   var fname = $('#fname').value();
   
   $.post("./index/save", "fname="+fname, alert("fucku"));
   
   event.preventDefault();
   return false;
}


Is this the proper way of doing it? What am I missing? Thanks :)

Author:  bitWISE [ 11-19-2009 10:44 AM ]
Post subject:  Re: Zend/jQuery interaction

Try using this, rather than post:
http://docs.jquery.com/Ajax/jQuery.ajax

Code:
$.ajax({
   type: "POST",
   url: "./index/save",
   data: "fname=" + fname,
   success: function(msg){
     alert( "Data Saved: " + msg );
   }
});

Author:  ^misantropia^ [ 11-19-2009 11:05 AM ]
Post subject:  Re: Zend/jQuery interaction

I somehow missed this one but anyway, here goes. Replace this:
Code:
$.post("./index/save", "fname="+fname, alert("fucku"));

With this:
Code:
$.post('save', $('#myform').serialize(), function(response) { alert(response); });

Dinner time now, but I'll explain why later tonight.

Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/