我是zend框架和ajax的初学者我尝试用ajax和zend做一个简单的代码,当按下按钮时它包含一个div、文本和按钮文本的值被填充到div中但是当我按下按钮时什么也没发生:S这是我的代码,请帮助我
这是布局
/index/test.phtml
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<!--for display text and submit fields i use viewHelpers it's very comfortable and easy way.-->
<div class="submit_area">
<?php echo $this->formText('message', 'empty', array('size' => 32, 'id' => 'message')) ?>
<?php echo $this->formSubmit('submitTo', 'submit', array('id' => 'submitTo')) ?>
<div class="show-msg"></div>
</div>
<script >
//for send data i'll use jquery library
$(document).ready( function() {
<?php echo "ready" ?>
//By clicking on button submit condition makes validate on empty message
//unless field message will be not empty , the programm make send data to
//controller via ajax
$("#submitTo").click(function() {
var message = $('#message').val();
if (message != '') {
//run ajax
$.post('index/ajax', {'message' : message},
//callback function
function (respond) {
//put respond in class show-msg
$(".show-msg").html(respond);
}
);
}
});
});
</script>
------------------------------------------
这是控制器中的代码
class IndexController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function checkAction()
{
// action body
$request = $this->getRequest()->getPost();
//referring to the index
//gets value from ajax request
$message = $request['message'];
// makes disable renderer
$this->_helper->viewRenderer->setNoRender();
//makes disable layout
$this->_helper->getHelper('layout')->disableLayout();
//return callback message to the function javascript
echo $message;
}
public function testAction()
{
// action body
}
}