2012-04-25 55 views
1

因此,我正在使用jQuery .load()調用在CakePHP Web應用程序中實現無窮無盡的分頁。Ajax和jQuery的500內部錯誤.Load()函數,直接訪問url直接工作正常。 1and1服務器

下面是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(); 

      } 
     }); 

這裏最重要的部分是$ .load(),它嘗試加載一個URL(http://www.MYWEBSITE.com/posts/index/page :2)。當jQuery發出請求時,服務器返回500內部服務器錯誤如果我使用jQuery.ajax(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> 

的.htaccess CakePHP中的應用程序/:

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


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

CakePHP中的.htaccess 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> 

任何幫助或見解都非常感謝!

回答

0

所以事實證明,這是一個問題,我改變了由Cake渲染哪個視圖的方式,這取決於調用是否是AJAX。

本來我有這個,改變所呈現的觀點:我的哪個地方發展服務器上的完美無缺

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 
} 

我猜它有一個事實,即實際文件夾「的帖子」有國會大廈P和我的Windows服務器不區分大小寫做所以「/ posts」解析爲「/ Posts」,但是一旦我將它放在1and1的linux服務器上,情況就成了問題。在閱讀CakePHP文檔後,我意識到我甚至不需要該目錄,因爲視圖來自同一個控制器。因此產生的代碼。

1

安裝Wireshark並確定瀏覽器導航到頁面時與使用AJAX請求瀏覽器時請求之間的差異。

http://www.wireshark.org/

只有這樣,你將擁有的問題是什麼更好的主意。

+0

感謝您的想法,區別在於一個是AJAX請求,另一個是香草GET。這讓我看到了我的控制器代碼,我記得我有一個檢查,當請求是AJAX時,會更改使用哪個Layout來呈現請求。對此進行評論會修復Ajax請求,並且它可以正常工作。雖然沒有正確,因爲我有一個不同的佈局的理由。在我多玩這個之後更新我的問題。 – Dsyko 2012-04-25 14:58:24

+0

就HTTP協議而言,AJAX請求和「vanilla」請求之間沒有區別。差異在於瀏覽器如何處理信息。考慮到這一點,您應該能夠查看請求中的差異並確定問題,或者至少調整必要的設置以使AJAX請求模仿您的vanilla get,這樣您就不會觸發發生的任何服務器錯誤。 – 2012-04-25 15:35:07

1

試着用$ post來代替嗎? 當我的參數大於1時,我使用$ .post或get,$ .ajax作爲一個參數。

相關問題