0
這是我的嘗試,這是由onclick
事件執行!如何在zend中使用ajax(jquery)從控制器調用函數?
var post_array = {
data_post: postData
}; //Array
$.ajax({
url: "location/add-names",
type: "POST",
data: post_array,
success: function (data, textStatus, jqXHR) {
//data - response from server
},
error: function (jqXHR, textStatus, errorThrown) {
}
});
而且PHP代碼:
<?php
class LocationController extends \Lunchbox\Controller
{
public function indexAction()
{
...................
}
public function addNamesAction(){
echo 1;
}
}
路線:
$location = new Zend_Controller_Router_Route('locatie/:locationUrl/:day',
array('module' => 'default', 'controller' => 'location', 'day' => Cronos::getCurrentDayName()),
array('day' => Cronos::$weekDayRegex)
);
$router->addRoute('location', $location);
我想要的AJAX事件後顯示 「1」。但螢火蟲顯示我這個錯誤:「404未找到」。我是zend的新手,請給我一個合理的答案。 THX:d
現在顯示的debug.log我:
2014-04-14T09:57:09+03:00 CRIT (2): ----------------
2014-04-14T09:57:09+03:00 CRIT (2): URL: /location/add-names
2014-04-14T09:57:09+03:00 CRIT (2): script 'location/add-names.phtml' not found in path (/home/lunchbox/public_html/application/views/scripts/)
#0 /opt/ZendFramework-1.12.3/library/Zend/View/Abstract.php(884): Zend_View_Abstract->_script('location/add-na...')
#1 /opt/ZendFramework-1.12.3/library/Zend/Controller/Action/Helper/ViewRenderer.php(900): Zend_View_Abstract->render('location/add-na...')
#2 /opt/ZendFramework-1.12.3/library/Zend/Controller/Action/Helper/ViewRenderer.php(921): Zend_Controller_Action_Helper_ViewRenderer->renderScript('location/add-na...', NULL)
#3 /opt/ZendFramework-1.12.3/library/Zend/Controller/Action/Helper/ViewRenderer.php(960): Zend_Controller_Action_Helper_ViewRenderer->render()
#4 /opt/ZendFramework-1.12.3/library/Zend/Controller/Action/HelperBroker.php(277): Zend_Controller_Action_Helper_ViewRenderer->postDispatch()
#5 /opt/ZendFramework-1.12.3/library/Zend/Controller/Action.php(527): Zend_Controller_Action_HelperBroker->notifyPostDispatch()
#6 /opt/ZendFramework-1.12.3/library/Zend/Controller/Dispatcher/Standard.php(308): Zend_Controller_Action->dispatch('addNamesAction')
#7 /opt/ZendFramework-1.12.3/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#8 /opt/ZendFramework-1.12.3/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
#9 /opt/ZendFramework-1.12.3/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#10 /home/lunchbox/public_html/index.php(31): Zend_Application->run()
#11 {main}
CAND有人能幫助我嗎?
您已經添加了這條路你module.config.php?或者你是否使用其他限制,如ACL? – chrisblomm
請再次檢查我的帖子 – Chester
嘗試只給ajax的url中的addNames,如果不工作看看這個:http://stackoverflow.com/questions/8485726/using-jquery-to-post-data-in -zend-framework/8489447#8489447 – sandip