AJAX POST到web api使用Json - 500内部服务器错误

时间:2016-06-18 06:21:25

标签: jquery json ajax

我正在尝试使用ajax jquery - POST方法从客户端连接到web api 我的代码示例:

<script type="text/javascript">
$(document).ready(function (){
    $("#btn392").click(function () {
    alert("test");
    var url = "https://test.ie/V2/Core/Sessions";

    var data = { AuthenticationProvider: 0 };

    $.ajax({
        type: "POST",
        url: url,
        data: JSON.stringify(data),
        cache: false,
        crossDomain: true,
        dataType:'jsonp',
        contentType: 'application/json; charset=utf-8',
        headers: { 'Pz-ApplicationName': 'xxxx', 'Pz-ApplicationKey': yyyy','Access-Control-Allow-Origin':'*'},
        success: function (msg) {
            alert("Data Saved: " + msg);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert(errorThrown);
        },

    });    

    });
});
</script>

获得以下回复:

请求网址:

https://test.ie/V2/Core/Sessions?callback=jQuery18301695447497748852_1466229802951&{%22AuthenticationProvider%22:0}&_=1466230308713

请求方法:GET
状态代码:500内部服务器错误

远程地址:193.111.82.196:443

Response Headers
view source
Access-Control-Allow-Headers:Content-Type,Pz-Authorisation,X-Requested-With
Access-Control-Allow-Methods:POST,GET,PUT,DELETE,OPTIONS
Access-Control-Allow-Origin:*
Cache-Control:no-cache
Connection:close
Content-Length:409

Content-Type:application/json; charset=utf-8
Date:Sat, 18 Jun 2016 06:11:39 GMT
Expires:-1
Pragma:no-cache
Server:Microsoft-IIS/8.5

X-AspNet-Version:4.0.30319
X-Frame-Options:SAMEORIGIN
X-Powered-By:ASP.NET
Request Headers

view source
Accept:*/*
Accept-Encoding:gzip, deflate, sdch, br
Accept-Language:en-GB,en-US;q=0.8,en;q=0.6
Connection:keep-alive
Host:pwpservice-qa.test.ie
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2770.0 Safari/537.36
Query String Parameters
view source
view URL encoded
callback:jQuery18301695447497748852_1466229802951
{"AuthenticationProvider":0}:
_:1466230308713

尽管我正在尝试发布帖子,但它显示响应GET并引发内部服务器错误。非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

与消息一样,处理您的请求时,服务器上发生错误。服务器日志是检查以获取有关正在进行的操作的更多信息的最佳位置。如果您无权访问它们,则可以打开浏览器的开发者模式(它们都有一个)以原始形式调试请求。