views:

1614

answers:

2

I'm just getting into Dojo and wanted to try a simple AJAX Post like the examples on Dojo's website.

Here is the HTML/JS:

<form method="POST" id="addProjectForm">
<dl>
 <dt>Project Name:</dt>
  <dd><input dojoType="dijit.form.TextBox" id="projectName"></dd>
 <dt>Project Description:</dt>
  <dd><textarea dojoType="dijit.form.Textarea" id="projectDescription" style="width: 300px; height: 100px"></textarea></dd>
</dl>

<button dojoType="dijit.form.Button" style="float: right">
 Save Project
 <script type="dojo/method" event="onClick">
  dojo.xhrPost({
   url: '/projects/add/',
   load: function(data, ioArgs) {
    alert(data);
   },
   error: function(data, ioArgs) {
    alert('There was an error');
   },
   form: 'addProjectForm'
  });
 </script>
</button>
</form>

and on the backend I have the following:

class ProjectsController extends Zend_Controller_Action
{
public function addAction()
{
 $this->_helper->layout->disableLayout();
 $this->_helper->viewRenderer->setNoRender(true);

 $projectName = $this->_request->getParam('projectName');
 $description = $this->_request->getParam('projectDescription');

 print_r($_POST);
}
}

When I click the 'Save Project' button, I get a JS alert box with php output of an empty array so none of the information is getting posted. What am I doing wrong?

+1  A: 

This is because of a stupid mistake. I didn't have a name set on any of the form elements, only IDs.

dragonmantank
A: 

As I have been playing with POSTing data through Dojo last night, I have one small remark.

dojo.xhrPost() seem only to work in last version of Dojo Toolkit, when using previous versions you are locked to dojo.io.iframe.send(), if you want to handle the response server gives you after POSTing data. Documentation is bit unclear on this.

dond