I'm trying to mash a proof of concept together and have the following rough code snippet in there...
var jenkinsBuilds = [
{url:"http://jenkins.server:8080/view/project/job/build_type1/", x:100, y:100},
{url:"http://jenkins.server:8080/view/project/job/build_type2/", x:200, y:200}
];
function createBuild(buildData) {
var divBuild = document.createElement("div");
divBuild.className = "buildNode";
divBuild.title = buildData.url;
divBuild.style.left = buildData.x + "px";
divBuild.style.top = buildData.y + "px";
backdrop.appendChild(divBuild);
var obj = document.createElement("object");
obj.onload = loadedObj;
obj.type = "text/html";
obj.data = buildData.url + "api/json?tree=builds[number]";
divBuild.appendChild(obj);
}
function loadedObj(e) {
alert(e.srcElement);
}
The alert comes up with [object HTMLObjectElement]
.
I'm wanting to get the json contents of the object into a var json =
variable to do a JSON.parse() on later, but I don't know how to get the json contents out of the object.
When I look at the object in the Chrome DOM inspector, it has...
<div>
L <object>
L #document
L <html>
L <head></head>
L <body>
L <pre>
"{"builds":[{"number":3431},{"number":3430},{"number":3429},{"number":3428},{"number":3427}]}"
</pre>
So I can see the json contents in the innerText of the node in the inspector.
But - the <object>
has childElementCount: 0
and the #document has ownerDocument: null
and parentNode: null
- so how can I get access to the <pre>
's json innerText
?
I would prefer to use plain javascript rather than jQuery if possible (for ease of maintainability if I get hit by a truck).
This is not intended for public use, and will be run on the latest browsers (99% Chrome and Firefox).
Thanks for any help.