【问题标题】:Debugging jQuery ajax 500 Internal server error调试 jQuery ajax 500 内部服务器错误
【发布时间】:2013-02-23 10:21:54
【问题描述】:

我的工作 CodeIgniter 网站在 MediaTemple 上托管时出现 500 内部服务器错误。它发生在 jQuery Ajax 调用期间。

我不知道出了什么问题。是控制器的错误还是模型的错误?我的 Ajax 调用:

$.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 已返回给我&lt;p&gt;The action you have requested is not allowed.&lt;/p&gt;。但这意味着什么?

【问题讨论】:

  • 我不明白为什么你在success: function(msg) 有味精,如果你在这个功能中甚至不使用它?检查发布到控制器/从控制器接收的变量是否是好的类型。
  • 500 表示服务器错误,不是你的jQuery代码问题,是服务器问题。
  • @BenjaminGruenbaum 好的,我知道问题出在服务器代码上。但是我要如何调试呢?
  • 我认为对于这个 ajax 调用,您使用“Post”,而您是如何实现控制器的,它接受“Post”调用还是“Get”调用?您的控制器中是否映射了 url?

标签: jquery ajax


【解决方案1】:

您可以尝试在错误回调中使用alert(xhr.responseText); 或console.log(xhr.responseText);(后者将显示在您的浏览器控制台中,例如firebug),这样做您可以获得与异常相关的消息(如果有)。

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);
       }

【讨论】:

  • 好的答案不是直接的,而是让我找到了解决方案。谢谢
  • 对于其他直接回答对我有用的人。授予 IIS_IUSRS 访问权限以写入/修改放置文件的文件夹安全性。 responseText 帮助查明了错误。
  • jquery POST 方法的完美调试代码,可能在 .php 文件中有一些错误! +1 !
【解决方案2】:

请看我的回复here。它是关于如何使用 CodeIgniter 和 jQuery 进行 ajax 调试的完整解释。

【讨论】:

    【解决方案3】:

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

     <system.web>
    
        <webServices>
          <protocols>
            <add name="HttpPost" />
          </protocols>
        </webServices>
     </system.web>
    

    【讨论】:

      猜你喜欢
      • 2019-12-10
      • 2013-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-10
      • 2013-05-10
      相关资源
      最近更新 更多