调试 jQuery ajax 500 内部服务器错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15284413/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 14:43:56  来源:igfitidea点击:

Debugging jQuery ajax 500 Internal server error

jqueryajax

提问by Himanshu Yadav

My working CodeIgniter site is giving a 500 Internal Server Error while hosting it on MediaTemple. It is happening during a jQuery Ajax call.

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

I have no idea what could have gone wrong. Is the error from the controller or the model? My Ajax call:

我不知道出了什么问题。是控制器的错误还是模型的错误?我的 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 has returned me <p>The action you have requested is not allowed.</p>. But what does that mean?

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

回答by Snivs

You can try using alert(xhr.responseText);or console.log(xhr.responseText);(the later will show up in your browser console e.g. firebug) in your error callback, doing so you can get the message associated with the exception (if any).

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

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

or

或者

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

回答by Gustavo Rubio

Please see my response here. It is a full explanation on how to do ajax debugging with CodeIgniter and jQuery.

在此处查看我的回复。这是关于如何使用 CodeIgniter 和 jQuery 进行 ajax 调试的完整说明。

回答by Francisco Prestes

You need to configure the webconfig file to receive POST request.

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

 <system.web>

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