2013-03-08 67 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> 
相关问题