0

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.


Have a look at the org.apache.camel.component.restlet.DefaultRestletBinding class. By default form data is only bound when content type is "application/x-www-form-urlencoded". Also, only URI template values will be bound to headers.

To get at arbitrary query parameters you can do something like:

Request request = exchange.getIn().getHeader(RestletConstants.RESTLET_REQUEST, Request.class);
String value = request.getResourceRef().getQueryAsForm().getFirstValue("foo");

Also, the raw query string will be available in the CamelHttpQuery header.

You can supply your own class which implements RestletBinding (or extend DefaultRestletBinding) by specifying the bean ID of a RestletBinding object in the Camel Registry using the 'restletBinding' endpoint query option. If you are using Spring register a bean like this:

    <bean id="myRestletBinding" class="com.example.MyRestletBinding"/>
4

1 に答える 1

1

私の理解が正しければ、あなたが含めた にはメイン コードとは異なるドメインがあり、 Same-origin policy の<object>餌食になります。別のドメインを編集してCORSを設定するか、オプションで Chrome を実行しない限り、ブラウザーから別のドメインにアクセスすることはできません。--disable-web-security

于 2013-10-03T10:55:56.483 に答える