我剛進入Dojo並想嘗試一個簡單的AJAX Post,如examples在 Dojo的網站上。dojo.xhrPost不發送任何數據
下面是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>
,並在後端我有以下幾點:
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);
}
}
當我點擊 '保存項目' 按鈕,我得到一個JS警告框與PHP輸出一個空的數組,所以沒有任何信息發佈。我究竟做錯了什麼?