Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Zend Framework中从Jquery调用控制器操作时出现404(找不到页面)错误_Php_Jquery_Ajax_Zend Framework - Fatal编程技术网

Php 在Zend Framework中从Jquery调用控制器操作时出现404(找不到页面)错误

Php 在Zend Framework中从Jquery调用控制器操作时出现404(找不到页面)错误,php,jquery,ajax,zend-framework,Php,Jquery,Ajax,Zend Framework,我是Zend Framework的新手,我正在尝试使用Jquery从indexController.php文件调用action方法,这次我遇到了错误: Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost/zf_demo/public/index/process My Code is : IndexController.php public functio

我是Zend Framework的新手,我正在尝试使用Jquery从indexController.php文件调用action方法,这次我遇到了错误:

Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost/zf_demo/public/index/process

My Code is : IndexController.php

public function processAction() {
    echo "Successfully Called processAction";
}
我使用以下代码调用此操作:

    $.ajax({
        type: "POST",           
        url: "http://localhost/zf_demo/public/index/process",
        success: function() {
            alert("AJAX call a success!");
        },
        error: function() {
              alert("AJAX call an epic failure");
        }
    });
.htaccess文件:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
如需更多帮助:

1)application.ini

[production]

phpSettings.display_startup_errors = 0
phpSettings.display_errors = 1
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 1



[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1

[config]
resources.db.adapter = PDO_MYSQL
resources.db.isDefaultAdapter = true
resources.db.params.host = localhost
resources.db.params.username = root
resources.db.params.password = 
resources.db.params.dbname = pankaj_test
2) Bootstrap.php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    protected function _initController()
    {
        $this->_frontcontroller = Zend_Controller_Front::getInstance();
        $this->_frontcontroller->setControllerDirectory(APPLICATION_PATH . 'controllers/');
    }

    protected function _initRoute()
    {
        $this->_route = $this->_frontcontroller->getRouter();
        $this->_route->addRoute('default', new Zend_Controller_Router_Route(
            ':controller/:action/*', array(
                'module'     => 'default',
                'controller' => 'index',
                'action'     => 'index'
            )
        ));
    }


    public function run()
    {
        try {
            $this->_frontcontroller->dispatch();
        }
        catch (Exception $e) {
            print nl2br($e->__toString());
        }
    }

    protected function _initDb()
    {
      $configData=array(
            'database' => array(            
            'adapter' => 'Pdo_Mysql',           
            'params' => array(          
                            'host' => 'localhost',                          
                            'username' => 'root',                           
                            'password' => '',                           
                            'dbname' => 'pankaj_test')
            )
        );

        $config=new Zend_Config($configData);

        $db=Zend_Db::factory($config->database);

        //$db = Zend_Db_Table_Abstract::getDefaultAdapter();

        Zend_Db_Table::setDefaultAdapter($db);





    }

}
My index.php(来自公用文件夹)


您需要省略“public”一词。因此,URL应该是:

url: "http://localhost/zf_demo/index/process",

您是否已禁用该视图? 此外,如果布局在默认情况下处于启用状态,则应禁用布局。 您可以通过在操作末尾添加exit来解决此问题

public function processAction() {
    echo "Successfully Called processAction";
    exit;
}
还要检查应用程序_ENV是否为开发而不是生产。否则它将不会显示错误


最后,通过访问
http://localhost/zf_demo/public/index.php/index/process
。如果这样做有效,则.htaccess会出现问题。

如果您在本地服务器中指定了一个虚拟主机,这将非常容易

编辑apache的httpd.conf并添加(在文件末尾):


现在运行
http://127.0.0.15

使用重写缺少htaccess?请立即检查…我已添加了代码。如果您直接在浏览器中访问它,而不是使用Ajax访问它,是否有效?否…当时我收到错误:在该服务器上找不到请求的URL/zf_demo/public/index/process如果您尝试直接在浏览器中访问页面localhost/zf_demo/public/index/process,它有效吗?在你的引导程序中注释掉_initRoute并检查它是否有效。@Rijandael:仍然不起作用…还有一件事404错误是apache的,而不是zend的…这有什么区别吗?正如你所说,我在“processAction()”的末尾添加了“exit”…但它仍然不起作用:(另外,我已将index.php中的应用程序_ENV从“生产”改为“开发”。对于更多参考资料,我将发布index.php,请检查其中是否还有任何错误。
public function processAction() {
    echo "Successfully Called processAction";
    exit;
}
<VirtualHost 127.0.0.15:80>
    ServerName 127.0.0.15
    DocumentRoot "C:\zf_demo\public" // or whatever is the path to the index.php

    <Directory "C:\zf_demo\public"> // you might need to modify this part 
        DirectoryIndex index.php    // depending on Apache's version in use
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>
url: "http://localhost/zf_demo/public/index/process",
url: "/index/process",