admin管理员组文章数量:1022964
<html>
<head>
<script src=".10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$.ajax({
type: "GET",
dataType: 'jsonp',
url: "",
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>
While running the above code I am getting SyntaxError: missing ; before statement error. I read somewhere Access-Control-Allow-Origin should be used to solve problem. But I don't find a good documentation anywhere about how to use with Jira.
"UPDATE"
The above error I am getting if I have already loggedin in jira. If I logout in jira and then run the above code then getting error "NetworkError: 401 Unauthorized - ;_=1388216960966"
It seems the above code has two problem. 1. It is not able to authenticate in jira. 2. if we already authenticate in jira (that means browser has cookies)and make the request then syntax error is shown because of jsonp.
<html>
<head>
<script src="http://ajax.googleapis./ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$.ajax({
type: "GET",
dataType: 'jsonp',
url: "http://myJira./rest/api/2/issue/MA-6614/ment",
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>
While running the above code I am getting SyntaxError: missing ; before statement error. I read somewhere Access-Control-Allow-Origin should be used to solve problem. But I don't find a good documentation anywhere about how to use with Jira.
"UPDATE"
The above error I am getting if I have already loggedin in jira. If I logout in jira and then run the above code then getting error "NetworkError: 401 Unauthorized - http://myjira./rest/api/2/issue/MA-6614/ment?callback=jQuery1102010440085066514837_1388216960965&_=1388216960966"
It seems the above code has two problem. 1. It is not able to authenticate in jira. 2. if we already authenticate in jira (that means browser has cookies)and make the request then syntax error is shown because of jsonp.
Share Improve this question edited Dec 28, 2013 at 9:27 Mohammad Adnan asked Dec 28, 2013 at 7:31 Mohammad AdnanMohammad Adnan 6,6276 gold badges32 silver badges47 bronze badges 4- you have to post username and pwd to url right? – Sridhar R Commented Dec 28, 2013 at 7:34
- NO. I have to add username and password in http hearder. something like AUTHENTICATION : "usrname:password" And jquery does it for u if u use username and password keys. – Mohammad Adnan Commented Dec 28, 2013 at 7:39
- @MohdAdnan, so isn't possible to make it just with using javascript? – Pmt Commented Jan 30, 2014 at 16:58
- 1 @PimentaDev. They revoked support. Not possible now. You have to use server side authentications. refer the below answer for details. – Mohammad Adnan Commented Feb 1, 2014 at 7:22
2 Answers
Reset to default 3So I got the answer. Support in jira is revoked for authenticating from javascript. Iitally jsonP was the option but now it is not possible. We have to do server side authentication of jira. Example here
https://developer.atlassian./display/JIRADEV/JIRA+REST+API+Example+-+Basic+Authentication
You can do this with javascript.
function request(){
var xhr = getXHR();
xhr.addEventListener("error", transferFailed, false);
xhr.addEventListener("abort", transferCanceled, false);
xhr.open("GET", baseURL+"/rest/api/2/issue/KEY-1", false);
xhr.setRequestHeader("Authorization", "Basic "+btoa("admin:admin"))
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send();
}
Ensure that it is synchronous and jira server conf has:
Header always set Access-Control-Allow-Credentials "true" Header set Access-Control-Allow-Headers "Authorization, Origin, X-Requested-With, Content-Type, Accept"
<html>
<head>
<script src=".10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$.ajax({
type: "GET",
dataType: 'jsonp',
url: "",
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>
While running the above code I am getting SyntaxError: missing ; before statement error. I read somewhere Access-Control-Allow-Origin should be used to solve problem. But I don't find a good documentation anywhere about how to use with Jira.
"UPDATE"
The above error I am getting if I have already loggedin in jira. If I logout in jira and then run the above code then getting error "NetworkError: 401 Unauthorized - ;_=1388216960966"
It seems the above code has two problem. 1. It is not able to authenticate in jira. 2. if we already authenticate in jira (that means browser has cookies)and make the request then syntax error is shown because of jsonp.
<html>
<head>
<script src="http://ajax.googleapis./ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$.ajax({
type: "GET",
dataType: 'jsonp',
url: "http://myJira./rest/api/2/issue/MA-6614/ment",
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>
While running the above code I am getting SyntaxError: missing ; before statement error. I read somewhere Access-Control-Allow-Origin should be used to solve problem. But I don't find a good documentation anywhere about how to use with Jira.
"UPDATE"
The above error I am getting if I have already loggedin in jira. If I logout in jira and then run the above code then getting error "NetworkError: 401 Unauthorized - http://myjira./rest/api/2/issue/MA-6614/ment?callback=jQuery1102010440085066514837_1388216960965&_=1388216960966"
It seems the above code has two problem. 1. It is not able to authenticate in jira. 2. if we already authenticate in jira (that means browser has cookies)and make the request then syntax error is shown because of jsonp.
Share Improve this question edited Dec 28, 2013 at 9:27 Mohammad Adnan asked Dec 28, 2013 at 7:31 Mohammad AdnanMohammad Adnan 6,6276 gold badges32 silver badges47 bronze badges 4- you have to post username and pwd to url right? – Sridhar R Commented Dec 28, 2013 at 7:34
- NO. I have to add username and password in http hearder. something like AUTHENTICATION : "usrname:password" And jquery does it for u if u use username and password keys. – Mohammad Adnan Commented Dec 28, 2013 at 7:39
- @MohdAdnan, so isn't possible to make it just with using javascript? – Pmt Commented Jan 30, 2014 at 16:58
- 1 @PimentaDev. They revoked support. Not possible now. You have to use server side authentications. refer the below answer for details. – Mohammad Adnan Commented Feb 1, 2014 at 7:22
2 Answers
Reset to default 3So I got the answer. Support in jira is revoked for authenticating from javascript. Iitally jsonP was the option but now it is not possible. We have to do server side authentication of jira. Example here
https://developer.atlassian./display/JIRADEV/JIRA+REST+API+Example+-+Basic+Authentication
You can do this with javascript.
function request(){
var xhr = getXHR();
xhr.addEventListener("error", transferFailed, false);
xhr.addEventListener("abort", transferCanceled, false);
xhr.open("GET", baseURL+"/rest/api/2/issue/KEY-1", false);
xhr.setRequestHeader("Authorization", "Basic "+btoa("admin:admin"))
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send();
}
Ensure that it is synchronous and jira server conf has:
Header always set Access-Control-Allow-Credentials "true" Header set Access-Control-Allow-Headers "Authorization, Origin, X-Requested-With, Content-Type, Accept"
本文标签: jqueryJira rest client in javascript giving errorStack Overflow
版权声明:本文标题:jquery - Jira rest client in javascript giving error - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745580030a2157253.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论