duanmu6752 2016-06-17 14:21 采纳率: 0%
浏览 62

AJAX和PHP引用时出错

I've been looking at this for a while and I think the major issue is the file i am referencing but I am not sure. I am working with a large amount of php files scattered all over the project folder but in the immediate folder I am working with files NavBar.php which is called using a require() statement in layout.php here's the code I am having trouble with (btw all of this code is in 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
                    }
                }
                ?>  

I know the sql calls are outdate and I should change it to PDOs I will make the switch as soon as I can figure out why the AJAX isn't working. this php code makes a db call and retrieves some data which displayed in the li (new li generated for each row in the table)(dropdown) and when a user clicks it I want to use this JS function to save the index of the clicked li to a php variable (hence the AJAX, I am really new to AJAX so I am having trouble figuring it out):

        <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>

I think the major issue might be the file I am referencing since NavBar.php is referenced by layout.phtml which is probably required by some other document in the hierarchy. this is the error I get in the console when I click on the li:

jquery.min.js:4 XHR finished loading: POST "http://localhost/shiprequest/layout.phtml".send @ jquery.min.js:4ajax @ jquery.min.js:4(anonymous function) @ shiprequest?lang=en:235dispatch @ jquery.min.js:3r.handle @ jquery.min.js:3 shiprequest?lang=en:240
( ! ) Fatal error: Uncaught exception 'Zend_Acl_Exception' with message 'Resource 'shiprequest_layout.phtml' not found' in C:\sgm\library\Zend\Acl.php on line 364 ( ! ) Zend_Acl_Exception: Resource 'shiprequest_layout.phtml' not found in C:\sgm\library\Zend\Acl.php on line 364 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

  • 写回答

1条回答 默认 最新

  • duanmei1350 2016-06-17 14:28
    关注

    From the message error provided by you:

    Uncaught exception 'Zend_Acl_Exception' with message 'Resource 'shiprequest_layout.phtml' not found

    Validate if shiprequest_layout.phtml exist. You probably wanted to write shiprequest_layout.html and not .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>
    

    EDIT from Comments:

    If you file is really layout.phtml, then your error is in file Acl.php (C:\sgm\library\Zend\Acl.php) at line 364. Line 364 is trying to find shiprequest_layout.phtml if this file do not exist, you will get this error.

    You probably mean layout.phtml instead of shiprequest_layout.phtml

    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记