Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.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 在ajax调用中不执行Require_once_Php_Ajax_Require Once - Fatal编程技术网

Php 在ajax调用中不执行Require_once

Php 在ajax调用中不执行Require_once,php,ajax,require-once,Php,Ajax,Require Once,这是我的'index.php'文件(它的一部分): 在#blog_main_content div中,我通过ajax调用注入'articleLoader.php',效果良好。 “blog_list.php”第一次显示得很好。 当用户通过ajax调用返回“blog_list.php”时,我得到以下错误: 致命错误:在第8行的C:\wamp\www\kapantzakis_2.14\pages\blog_list.php中找不到类“Database” 我认为当ajax调用此文件时,php不会在“bl

这是我的'index.php'文件(它的一部分):

在#blog_main_content div中,我通过ajax调用注入'articleLoader.php',效果良好。 “blog_list.php”第一次显示得很好。 当用户通过ajax调用返回“blog_list.php”时,我得到以下错误:

致命错误:在第8行的C:\wamp\www\kapantzakis_2.14\pages\blog_list.php中找不到类“Database”

我认为当ajax调用此文件时,php不会在“blg_list.php”中执行require_一次

我不知道我是否解释得很好

谢谢你的帮助

编辑#1

Ajax调用:

// Perform the ajax call
        function getAjaxPage(method, content, currentOffset) {

            var temp_content = $('.temp_content');                      
                var temp_content_last = temp_content.filter(':last');

            var blog_main_content = $('#blog_main_content');                    
                var blog_main_content_first = blog_main_content.filter(':first');

                // Insert the html data in to the first or last div depending on the movement of the page
                if (method == 'next') {
                    var insert_div = temp_content_last;
                } else if (method == 'prev') {
                    var insert_div = blog_main_content_first;
                }

                // Get article or the article list
                if (content == 'article') {
                    var page = 'articleLoader.php';
                } else if (content == 'article_list') {
                    var page = 'pages/blog_list.php';                       
                }
                /*
                var lang = getCurLang();
                var data = 'lang=' + lang + '&art_id=' + art_id;*/

                var tags_wrapper = $('#tags_wrapper');

            $.ajax({
                url: page,  
                type: "GET",    
                /*data: data,*/
                cache: false,
                success: function (html) {                          
                    insert_div.html(html)
                        .queue(function() {
                            var return_to_list = $('#return_to_list');                              
                            return_to_list.attr('data-offsetTop', currentOffset);   
                            returnTopOffset();
                            if (content == 'article') {
                                tags_wrapper.fadeIn(800);
                            } else if (content == 'article_list') {
                                tags_wrapper.hide();
                            }                               
                            $(this).dequeue();
                        });
                }       
            });
            return $(this);
        }

您可以得到所有错误

我假设您的文件夹结构如下所示:

kapantzakis_2.14/
  articleLoader.php
  blog.php
  blog_list.php
  index.php
  pages/
    home.php
  phpScripts/
    Database.php
您的AJAX调用直接请求
pages/blog\u list.php
,但在您的问题文本中,
blog\u list.php
似乎位于您的根目录中(
kapantzakis\u 2.14


您得到的错误([…]
'Database'未在C:\wamp\www\kapantzakis_2.14\pages\blog_list.php
[…])显示
博客列表。php
位于
页面
-文件夹中。您的
glob
-调用在
pages
-文件夹中找不到名为
phpscript
的目录,因此
required\u once
调用永远不会执行。

Er,AJAX调用在哪里?我只看到一个PHP包含。我曾经尝试过require_(“$filename”);但是同样的事情发生了,我不认为这是一个好主意,但是你试过
include(“$filename”)也是吗?如果你这么做了,结果会怎样?伊格纳西奥,我试过了,但没有解决!问题是,当它通过“blog.php”包含时,它可以工作,但当通过ajax调用“blog_list.php”时,php不会执行“require_once”为什么不使用require或include?谢谢robbi!这似乎就是问题所在!
foreach (glob("phpScripts/*.php") as $filename) {
    require_once $filename;
}

// Create the $db object
$db = Database::obtain(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE); 

// Connect to the database
$db->connect();

$dbQuery = new databaseQuery();     

// Get the language from loader.php
$cur_lang = "'".$_SESSION['language']."'";

$dbQuery->getArticleList($cur_lang);

 ?>
// Perform the ajax call
        function getAjaxPage(method, content, currentOffset) {

            var temp_content = $('.temp_content');                      
                var temp_content_last = temp_content.filter(':last');

            var blog_main_content = $('#blog_main_content');                    
                var blog_main_content_first = blog_main_content.filter(':first');

                // Insert the html data in to the first or last div depending on the movement of the page
                if (method == 'next') {
                    var insert_div = temp_content_last;
                } else if (method == 'prev') {
                    var insert_div = blog_main_content_first;
                }

                // Get article or the article list
                if (content == 'article') {
                    var page = 'articleLoader.php';
                } else if (content == 'article_list') {
                    var page = 'pages/blog_list.php';                       
                }
                /*
                var lang = getCurLang();
                var data = 'lang=' + lang + '&art_id=' + art_id;*/

                var tags_wrapper = $('#tags_wrapper');

            $.ajax({
                url: page,  
                type: "GET",    
                /*data: data,*/
                cache: false,
                success: function (html) {                          
                    insert_div.html(html)
                        .queue(function() {
                            var return_to_list = $('#return_to_list');                              
                            return_to_list.attr('data-offsetTop', currentOffset);   
                            returnTopOffset();
                            if (content == 'article') {
                                tags_wrapper.fadeIn(800);
                            } else if (content == 'article_list') {
                                tags_wrapper.hide();
                            }                               
                            $(this).dequeue();
                        });
                }       
            });
            return $(this);
        }
// add this line on the top of your script
ob_start();


// add this line on the bottom of your script
$errors = ob_get_contents();
ob_end_clean();
$fopen = fopen('errors.txt', 'w+');
fwrite($fopen, $errors);
fclose($fopen);
kapantzakis_2.14/
  articleLoader.php
  blog.php
  blog_list.php
  index.php
  pages/
    home.php
  phpScripts/
    Database.php