Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.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
500 Ajax和jQuery.Load()函数的内部错误,直接访问url可以正常工作。1和1服务器_Jquery_Ajax_Cakephp - Fatal编程技术网

500 Ajax和jQuery.Load()函数的内部错误,直接访问url可以正常工作。1和1服务器

500 Ajax和jQuery.Load()函数的内部错误,直接访问url可以正常工作。1和1服务器,jquery,ajax,cakephp,Jquery,Ajax,Cakephp,因此,我使用jQuery.load()调用在CakePHP web应用程序中实现无休止的分页 以下是Javascript代码: $("#post_container").append('<div class="batch row" style="display:none;"></div>'); //append a container to hold ajax content var url = $("a#next").attr("href"); //ex

因此,我使用jQuery.load()调用在CakePHP web应用程序中实现无休止的分页

以下是Javascript代码:

$("#post_container").append('<div class="batch row" style="display:none;"></div>'); //append a container to hold ajax content
        var url = $("a#next").attr("href"); //extract the URL from the "next" link
        $(".paging").remove(); // remove the old pagination links because new ones will be loaded via ajax
        if(url === undefined)
        {
            $("#ajax_pagination_text").html("<strong>Turtles all the way down. No more posts :(</strong>");
        }

        $("div.batch").load(url, function(response, status, xhr) {
            if (status == "error") {
              var msg = "Sorry but there was an error: ";
              alert(msg + xhr.status + " " + xhr.statusText);
            }
            else {
                $(this).attr("class","loaded row"); //change the class name so it will not be confused with the next batch
                $(".paging").hide(); //hide the new paging links
                $(this).fadeIn();

            }
        });
$(“#post_容器”)。附加(“”)//附加一个容器来保存ajax内容
var url=$(“a#next”).attr(“href”)//从“下一个”链接中提取URL
$(“.paging”).remove();//删除旧的分页链接,因为新的分页链接将通过ajax加载
如果(url==未定义)
{
$(“#ajax_分页_文本”).html(“海龟一直向下。没有更多帖子:(”);
}
$(“div.batch”).load(url、函数(响应、状态、xhr){
如果(状态=“错误”){
var msg=“抱歉,出现错误:”;
警报(消息+xhr.status+“”+xhr.statusText);
}
否则{
$(this.attr(“class”,“loaded row”);//更改类名,以免与下一批混淆
$(“.paging”).hide();//隐藏新的分页链接
$(this.fadeIn();
}
});
这里的重要部分是$.load(),它尝试加载url(http://www.MYWEBSITE.com/posts/index/page:2)。当jQuery发出请求时,服务器返回一个500内部服务器错误。如果我使用jQuery.ajax(url);,则返回相同的错误。如果我直接转到该url,它将加载,没有问题

ajax调用在我的本地开发服务器上也可以正常工作。因此,这一定是我的主机1和1上的设置造成的。这里发生了什么?我已经用这个主机处理了500个服务器错误

我已将.htaccess文件更改如下,以修复以前的500个错误:

.htaccess在CakePHP根目录中:

<IfModule mod_rewrite.c>
   AddType x-mapp-php5 .php
   SetEnv PHP_VER

   RewriteEngine ON
   RewriteBase /
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

AddType x-mapp-php5.php
SetEnv PHP\u版本
重新启动发动机
重写基/
重写规则^$app/webroot/[L]
重写规则(*)app/webroot/$1[L]
.htaccess在CakePHP应用程序中/:

<IfModule mod_rewrite.c>
   AddType x-mapp-php5 .php


    RewriteEngine ON
    RewriteBase /
    RewriteRule    ^$    webroot/    [L]
    RewriteRule    (.*) webroot/$1    [L]
 </IfModule>

AddType x-mapp-php5.php
重新启动发动机
重写基/
重写规则^$webroot/[L]
重写规则(.*)webroot/$1[L]
.htaccess在CakePHP app/webroot/:

<IfModule mod_rewrite.c>
   AddType x-mapp-php5 .php
   AddHandler x-mapp-php5 .php

    RewriteEngine ON
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ /index.php?q=$1 [QSA,L]
</IfModule>

AddType x-mapp-php5.php
AddHandler x-mapp-php5.php
重新启动发动机
重写基/
重写cond%{REQUEST_FILENAME}!-d
重写cond%{REQUEST_FILENAME}!-f
重写规则^(.*)$/index.php?q=$1[QSA,L]

非常感谢您提供的任何帮助或见解!

安装Wireshark,并确定浏览器在导航到页面时发出的请求与使用AJAX发出的请求之间的差异

只有这样,您才能更好地了解问题所在。

尝试使用$post?。
当我的参数大于1时,我只使用$.post或get,$.ajax作为一个参数。

因此,我根据调用是否为ajax来更改Cake呈现的视图时发现这是一个问题

最初,为了更改渲染的视图,我使用了以下方法:

if ($this->RequestHandler->isAjax()) {  
   $this->render('/posts/ajax_paging');  // Special view for ajax pagination
}
这在我的本地开发服务器上运行得非常完美。但一旦上传,就会出现问题。服务器说它找不到视图

将其更改为以下选项可修复此问题:

if ($this->RequestHandler->isAjax()) {  
  $this->render('ajax_paging');  // Render a special view for ajax pagination
}

我猜这是因为实际文件夹“Posts”有一个capitol p,而且我的windows服务器不区分大小写,所以“/Posts”解析为“/Posts”但是,一旦我将它放在1的linux服务器上,1这个案例就成了一个问题。阅读CakePHP文档后,我意识到我甚至不需要目录,因为视图来自同一个控制器。因此产生了代码。

感谢这个想法,区别在于一个是AJAX请求,另一个是普通GET。这导致我开始查看我的控制器代码,我记得我检查了当请求是AJAX时,用于呈现请求的布局是否发生了变化。对此进行注释可以修复AJAX请求,并且它可以正常工作。尽管不正确,因为我有一个不同的布局。在我进一步研究之后更新我的问题。至于HTTP协议关注的是AJAX请求和“普通”请求之间没有区别请求。差异严格地取决于浏览器处理信息的方式。记住这一点,您应该能够查看请求中的差异并确定问题,或者至少调整任何必要的设置,以使AJAX请求模仿您的普通get,这样您就不会触发任何正在发生的服务器错误。