Quake3World.com Forums
     Programming Discussion
        Zend/jQuery interaction


Post new topicReply to topic
Login | Profile | | FAQ | Search | IRC




Print view Previous topic | Next topic 
Topic Starter Topic: Zend/jQuery interaction

Señor Shambler
Señor Shambler

Joined: 07 Mar 2006
Posts: 849
PostPosted: 11-04-2009 11:58 AM           Profile Send private message  E-mail  Edit post Reply with quote


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 :)




Top
                 

god xor reason
god xor reason

Joined: 08 Dec 1999
Posts: 21093
PostPosted: 11-19-2009 10:44 AM           Profile   Send private message  E-mail  Edit post Reply with quote


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 );
   }
});




Top
                 

Mentor
Mentor

Joined: 12 Mar 2005
Posts: 3958
PostPosted: 11-19-2009 11:05 AM           Profile Send private message  E-mail  Edit post Reply with quote


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.




Top
                 
Quake3World.com | Forum Index | Programming Discussion


Post new topic Reply to topic


cron
Quake3World.com
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group