【发布时间】:2016-06-18 06:21:25
【问题描述】:
我正在尝试使用 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 并引发内部服务器错误。非常感谢任何帮助。
【问题讨论】:
-
如果你有内部SERVER错误,你为什么要给我们JS代码?