2013-03-08 69 views
10

我的CodeIgniter網站在MediaTemple上託管時發出500內部服務器錯誤。它發生在jQuery Ajax調用期間。調試jQuery ajax 500內部服務器錯誤

我不知道會出現什麼問題。是來自控制器還是模型的錯誤?我的阿賈克斯電話:

$.ajax({ 
    url: "<?php echo site_url('invites/save_email') ?>", 
    type: 'POST', 
    data: form_data, 
    success: function(msg) { 
    window.location.href = "<?php echo site_url('invites/moreinvites')?>" 
     return true; 
    }, 
    error: function (xhr, ajaxOptions, thrownError) { 
     alert(xhr.status); 
     alert(thrownError); 
     alert(xhr.responseText); 
    } 
}); 

xhr.responseText已將我返回<p>The action you have requested is not allowed.</p>。但是,這是什麼意思?

+0

我不明白爲什麼你有msg in'success:function(msg)'如果你甚至不用它在這個函數中?檢查發佈到/從控制器接收的變量是否具有良好類型。 – 2013-03-08 00:16:46

+0

500意味着服務器錯誤,問題不在於你的jQuery代碼,問題在於服務器。 – 2013-03-08 00:20:29

+0

@BenjaminGruenbaum好吧,我明白這個問題是與服務器代碼。但我如何去調試它? – 2013-03-08 00:23:53

回答

39

您可以嘗試使用alert(xhr.responseText);console.log(xhr.responseText);在您的錯誤回調(稍後將在瀏覽器控制檯如螢火蟲顯示),這樣你可以得到異常(如果有的話)相關聯的消息。

error: function (xhr, ajaxOptions, thrownError) { 
      alert(xhr.status); 
      alert(xhr.responseText); 
      alert(thrownError); 
     } 

error: function (xhr, ajaxOptions, thrownError) { 
      console.log(xhr.status); 
      console.log(xhr.responseText); 
      console.log(thrownError); 
     } 
+1

好的答案不是一個直接的答案,但已採取我的解決方案。謝謝 – User 2015-05-25 10:39:21

+0

對於那些爲我工作的直接答案的人。在放置文件的位置爲IIS_IUSRS提供寫入/修改文件夾安全性的權限。 responseText幫助找出錯誤。 – 2016-03-05 19:14:39

0

請看看我的反應here。這是關於如何使用CodeIgniter和jQuery進行ajax調試的完整說明。

-1

您需要配置webconfig文件以接收POST請求。

<system.web> 

    <webServices> 
     <protocols> 
     <add name="HttpPost" /> 
     </protocols> 
    </webServices> 
</system.web> 
相關問題