I've been battling for 3 days trying to solve this and have 'google overload' - would love some help please.
We have a Jenkins build server located on http://jenkinsBuild.mycompany.com:8080
so if I enter this url into a browser...
http://jenkinsBuild.mycompany.com:8080/view/my_view/job/build_me/123/api/json?tree=result
... the browser page returns displaying...
{"result":"SUCCESS"}
Now, according to the Jenkins Wiki, "Jenkins provides machine-consumable remote access API to its functionalities" supporting json and jsonp through a REST API, which I believe should circumvent any same origin policy issues.
I am attempting (using the latest Chrome browser) to get that same json component {"result":"SUCCESS"}
.
I am using HTML/javascript with a $.getJSON()
call as described below. The HTML file currently resides on my local machine, but will probably eventually live on a wiki. Console outputs for the three urls are listed after the code.
How do I get the same json result I get by entering the url directly into the browser? Thanks for your help.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
var url1 = "http://jenkinsBuild.mycompany.com:8080/view/my_view/job/build_me/123/api/json?tree=result";
var url2 = "http://jenkinsBuild.mycompany.com:8080/view/my_view/job/build_me/123/api/json?tree=result&callback=?";
var url3 = "http://jenkinsBuild.mycompany.com:8080/view/my_view/job/build_me/123/api/json?callback=?&tree=result";
$('button').click(function(){
$.getJSON(url1, function(json) {
$("#reply").append("got callback: " + json);
});
});
});
</script>
</head>
<body>
<button>Get Jenkins</button><br />
<div id="reply">
</div>
</body></html>
CONSOLE OUTPUT FOR THE THREE URL's...
url1 -> XMLHttpRequest cannot load http://jenkinsBuild.mycompany.com:8080/view/my_view/job/build_me/123/api/json?tree=result. Origin null is not allowed by Access-Control-Allow-Origin.
url2 -> Uncaught SyntaxError: Unexpected token : json:1
url3 -> Uncaught SyntaxError: Unexpected token : json:1