Jquery 无法使用来自app的REST资源-415响应不是JSON格式
我正试图从一个独立的OpenSocial(Atlassian Jira)小工具中使用以下REST资源 我可以使用以下URL通过浏览器查询资源: 我可以从我的开发机器发出相同的请求。在我看来,它确实像JSON。。。然而,当我从我的小工具查询时,我得到Jquery 无法使用来自app的REST资源-415响应不是JSON格式,jquery,json,ajax,rest,jira,Jquery,Json,Ajax,Rest,Jira,我正试图从一个独立的OpenSocial(Atlassian Jira)小工具中使用以下REST资源 我可以使用以下URL通过浏览器查询资源: 我可以从我的开发机器发出相同的请求。在我看来,它确实像JSON。。。然而,当我从我的小工具查询时,我得到 GET 10.0.15.10:2990/jira/rest/api/latest/issue/CRD-1 415 Unsupported Media Type (32ms) 响应将作为HTML返回。这是tomcat的响应主体: <html
GET 10.0.15.10:2990/jira/rest/api/latest/issue/CRD-1 415 Unsupported Media Type (32ms)
响应将作为HTML返回。这是tomcat的响应主体:
<html><head><title>Apache Tomcat/6.0.20 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 415 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The server refused this request because the request entity is in a format not supported by the requested resource for the requested method ().</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/6.0.20</h3></body></html>
我曾尝试将数据类型:“json”
添加到ajax请求中,但没有效果。我可能错过了一些简单的东西
以下是请求/响应标题:
Response Headers
Content-Length 1051
Content-Type text/html;charset=utf-8
Date Sun, 10 Jun 2012 15:53:06 GMT
Server Apache-Coyote/1.1
X-AREQUESTID 1013x5993x1
X-ASESSIONID 1bi5et0
X-AUSERNAME admin
X-Seraph-LoginReason OK
Request Headers
Accept application/json, text/javascript, */*; q=0.01
Accept-Encoding gzip, deflate
Accept-Language en-gb,en;q=0.5
Connection keep-alive
Content-Type application/x-www-form-urlencoded
Cookie atlassian.xsrf.token=BP8Q-WXN6-SKX3-
DNT 1
Host 10.0.15.10:2990
Referer http://10.0.15.10:2990/jira/secure/Dashboard.jspa
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0
X-Requested-With XMLHttpRequest
尝试使用getJSON和out callBack=? 其中:
$.getJSON('https://jira.atlassian.com/rest/api/latest/issue/JRA-9jsoncallback=?', function(data){ $.each(data, function(){ alert(this.expand); }); });
尝试使用getJSON和out callBack=? 其中:
$.getJSON('https://jira.atlassian.com/rest/api/latest/issue/JRA-9jsoncallback=?', function(data){ $.each(data, function(){ alert(this.expand); }); });
小工具规范文件需要在ajax选项中发送contentType请求头:
args: [{
key: "issueData",
ajaxOptions: function() {
return {
contentType: 'application/json',
url: "/rest/api/2.0.alpha1/issue/CRDTRK-1"
};
},
}]
检查HTTP请求中的请求头。
应该是:内容类型:application/json
而不是:
Content-Type-application/x-www-form-urlencoded
您的小工具规范文件需要在ajax选项中发送contentType请求头:
args: [{
key: "issueData",
ajaxOptions: function() {
return {
contentType: 'application/json',
url: "/rest/api/2.0.alpha1/issue/CRDTRK-1"
};
},
}]
检查HTTP请求中的请求头。
应该是:内容类型:application/json
而不是:
Content-Type-application/x-www-form-urlencoded
,看起来415是本地机器的问题。。。看看这里。我可以从我的应用程序中查询其他rest资源,因此无法查看它与我的本地计算机的关联。我将发布firebug的请求/响应头…看起来415是本地机器的问题。。。看看这里。我可以从我的应用程序中查询其他rest资源,因此无法查看它与我的本地计算机的关联。我将发布firebug的请求/响应标题…谢谢,但仍然有问题。。。由于我正在查询Jira的本地实例,所以我的查询看起来是这样的:jQuery.getJSON('/rest/api/latest/issue/CRDTRK-1?jsoncallback=?',函数(data){$.each(data,function(){AJS.$(“”).append(this.expand);});但是现在我得到了这个错误:“missing:after property id”有什么想法吗?你能在类似浏览器的json结果中得到结果吗?当从浏览器访问REST URL时,页面被传输为内容类型:application/json,但是当我通过ajax请求访问同一资源时,它被传输为text/html。有没有办法强制响应以json形式返回?在api的文档中必须解释如何使用响应作为json检查谢谢,但仍然有问题…因为我正在查询Jira的本地实例,所以我的查询如下:jQuery.getJSON('/rest/api/latest/issue/CRDTRK-1?jsoncallback=?',function(data){$.each(data,function(){AJS.$(“”)。append(this.expand);});但是现在我遇到了这个错误:“缺少:在属性id之后”"有什么想法吗?你能在类似浏览器的json结果中得到结果吗?当从浏览器访问REST URL时,页面被传输为内容类型:application/json,但是当我通过ajax请求访问同一资源时,它被传输为text/html。有没有办法强制响应以json形式返回?在api的文档中必须解释如何将响应用作json检查