繁体   English   中英

AJAX和PHP引用错误

[英]Error with AJAX and PHP referencing

我已经看了一段时间了,我认为主要的问题是我正在引用的文件,但我不确定。 我正在处理散布在项目文件夹中的大量php文件,但在直接文件夹中,我正在处理NavBar.php文件,这是使用layout.php中的require()语句调用的,这是我遇到的代码(顺便说一下,所有这些代码都在NavBar.php中):

             <?php

                $db=mysql_connect('localhost','root','');
                if(!$db) {
                    die('Could not connect: '.mysql_error());
                }
                $connection_string=mysql_select_db('shipreq_stagetest',$db);
                $selectSQL='SELECT * FROM color_patterns';       
                $queryset=mysql_query($selectSQL);
                $num=mysql_num_rows($queryset);
                if(0==$num) {
                    echo "No record";
                    exit;
                } else {
                    while($row=mysql_fetch_assoc($queryset)) {?>
                    <li class= "list_item"  onclick="<?php $indx = $_POST['pat_id'];?>">
                        <?php echo($row['name']);?></li><?php
                    }
                }
                ?>  

我知道sql调用已过期,我应该将其更改为PDO,一旦我弄清楚为什么AJAX无法正常工作,就将进行切换。 此php代码进行数据库调用,并检索显示在li(为表中的每一行生成的新li)中显示的一些数据(下拉列表),当用户单击它时,我想使用此JS函数保存被单击的索引li到一个php变量(因此AJAX,我对AJAX真的很陌生,所以我很难弄清楚它):

        <script>

            $(document).on('click', '.list_item', function() {
                var indx = $(this).index();
                $.ajax({ // add ajax code here
                type: 'POST',
                url: 'layout.phtml',
                data: {pat_id: indx}, // send parameter like this
                success: function(response) {
                       console.log(response);
                }
                });
            });


        </script>

我认为主要问题可能是我正在引用的文件,因为NavBar.php被layout.phtml引用了,而层次结构中的某些其他文档可能会要求它。 这是我单击li时在控制台中遇到的错误:

jquery.min.js:4 XHR完成加载:POST“ http://localhost/shiprequest/layout.phtml ” .send @ jquery.min.js:4ajax @ jquery.min.js:4(匿名函数)@ shiprequest? lang = en:235dispatch @ jquery.min.js:3r.handle @ jquery.min.js:3 shiprequest?lang = en:240
( ! ) Zend_Acl_Exception: Resource 'shiprequest_layout.phtml' not found in C:\\sgm\\library\\Zend\\Acl.php on line Call Stack #TimeMemoryFunctionLocation 10.0006145888{main}( )..\\index.php : 0 20.0018168016require_once( 'C:\\sgm\\application\\bootstrap.php' )..\\index.php : 5 30.11182860576Zend_Controller_Front->dispatch( )..\\bootstrap.php : 124 (!)致命错误:第行的C:\\ sgm \\ library \\ Zend \\ Acl.php中出现未捕获的异常'Zend_Acl_Exception',消息为'资源'shiprequest_layout.phtml'(!)Zend_Acl_Exception:资源'shiprequest_layout.phtml'在第行的C:\\ sgm \\ library \\ Zend \\ Acl.php中找不到调用堆栈#TimeMemoryFunctionLocation 10.0006145888 {main}().. \\ index.php 0 20.0018168016require_once('C:\\ sgm \\ application \\ bootstrap.php ').. \\ index.php 5 30.11182860576Zend_Controller_Front-> dispatch().. \\ bootstrap.php 124

根据您提供的消息错误:

找不到消息为“资源'shiprequest_layout.phtml”的未捕获异常'Zend_Acl_Exception'

验证是否存在shiprequest_layout.phtml。 您可能想编写shiprequest_layout.html而不是.phtml

<script>

        $(document).on('click', '.list_item', function() {
            var indx = $(this).index();
            $.ajax({ // add ajax code here
            type: 'POST',
            url: 'layout.html',  <------ here
            data: {pat_id: indx}, // send parameter like this
            success: function(response) {
                   console.log(response);
            }
            });
        });


    </script>

编辑评论:

如果您的文件确实是layout.phtml,那么您的错误是file Acl.php (C:\\sgm\\library\\Zend\\Acl.php) at line 364 如果该文件不存在,则第364行尝试查找shiprequest_layout.phtml ,您将收到此错误。

您可能是指layout.phtml而不是shiprequest_layout.phtml

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM