2014-04-11 56 views
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有人能幫助我嗎?

+0

您已經添加了這條路你module.config.php?或者你是否使用其他限制,如ACL? – chrisblomm

+0

請再次檢查我的帖子 – Chester

+0

嘗試只給ajax的url中的addNames,如果不工作看看這個:http://stackoverflow.com/questions/8485726/using-jquery-to-post-data-in -zend-framework/8489447#8489447 – sandip

回答

0

我可以在這裏看到的情侶東西。

  1. 你已經證明這條路線是「/ locatie /:locationUrl /:天」但你需要的路線是「/位置/插件名稱在阿賈克斯
  2. - 您使用駱駝情況會顯示添加名稱的網址。大寫字母拆分與網址 -

希望幫助

+0

thx男人,但現在我沒有得到404錯誤,即時通訊得到:「500內部服務器錯誤」,任何ideea或提示,爲什麼?謝謝 – Chester

相關問題