<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$.ajax({
type: "GET",
dataType: 'jsonp',
url: "http://myJira.com/rest/api/2/issue/MA-6614/comment",
username : "myusrName",
password : "myPwd",
success: function (data) {
console.log( "Sample of data:", JSON.stringify(data));
},
error: function (errormessage) {
console.log( "errorMessage:", errormessage);
}
});
});
</script>
</head>
<body>
</body>
</html>
在运行上面的代码时,我得到了SyntaxError: missing ; 声明错误之前。我在某处读到 Access-Control-Allow-Origin 应该用来解决问题。但是我在任何地方都找不到关于如何使用 Jira 的好的文档。
“更新”
如果我已经登录 jira,我会遇到上述错误。如果我在 jira 中注销然后运行上述代码,则会出现错误“NetworkError: 401 Unauthorized - http://myjira.com/rest/api/2/issue/MA-6614/comment?callback=jQuery1102010440085066514837_1388216960965&_=1388216960966 ”
上面的代码似乎有两个问题。1. 无法在jira中进行身份验证。2. 如果我们已经在 jira 中进行了身份验证(这意味着浏览器有 cookie)并发出请求,那么由于 jsonp 会显示语法错误。