Plugin Development - Ajax Example

58 views
Skip to first unread message

Aytunc Beken

unread,
May 19, 2020, 9:35:15 AM5/19/20
to Jenkins Developers
Hi,

I am trying to implement Ajax call in UI page. I could only find this page (https://wiki.jenkins.io/display/JENKINS/AJAX+with+JavaScript+proxy) however it did not worked.

I will be glad if anyone can point some help.

- Documentation
- Plugin implemented Ajax
- Plugin implemented Jquery


Thanks a lot.

Oleg Nenashev

unread,
May 19, 2020, 9:57:27 AM5/19/20
to Jenkins Developers

Aytunc Beken

unread,
May 19, 2020, 9:58:51 AM5/19/20
to Jenkins Developers
I will check. Thanks!

Ullrich Hafner

unread,
May 19, 2020, 2:49:23 PM5/19/20
to Jenkins Developers
You can also have a look at some plugins that use the new JS UI components (bootstrap, charts, datatables). All of these plugins use Ajax to populate charts and tables: they also use the techniques described in the wiki and I can confirm that it works! What exactly is not working in your plugin?

The plugins that use these JA Ajax elements are 
- warnings plugin 
- forensics plugin
- autograding plugin


-- 
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/15189aee-5005-46a0-9569-36e24a70e02c%40googlegroups.com.

Gavin Mogan

unread,
May 19, 2020, 2:52:39 PM5/19/20
to Jenkins Developers
Ajax.Request is actually prototype, and I strongly recommend not using it, as its incredibly old and has messed with a lot of standard apis.

I recommend using jquery, or the native alternatives (XMLHttpRequest/fetch)

http://youmightnotneedjquery.com/ (search for ajax) has some good examples

Ullrich Hafner

unread,
May 19, 2020, 3:27:34 PM5/19/20
to Jenkins Developers
The problem with the alternatives is that they have no server counterpart. Or how do you route the requests to the Java model when using jQuery directly?

Gavin Mogan

unread,
May 19, 2020, 3:33:35 PM5/19/20
to Jenkins Developers
Uh, prototype is a frontend library, it doesn't actually expose things. I think any of the doName (like doAjax) expose as web GETters

var request = new XMLHttpRequest();
request.open('GET', "${it.baseUrl}/buildHistory/all", true);

request.onload = function() {
  if (this.status >= 200 && this.status < 400) {
    // Success!
    var hist = $$("buildHistory");

    var newhist = document.createElement('div');
    newhist.innerHTML = this.response.text;
    newhist.headers = hist.headers

    relace(hist, newhist);
    fireBuildHistoryChanged();
  } else {
    // We reached our target server, but it returned an error
  }
};

request.onerror = function() {
  // There was a connection error of some sort
};

request.send();

```


```
              new Ajax.Request("${it.baseUrl}/buildHistory/all",{
                method: "get",
                onComplete: function(rsp,_) {
                  <!-- neither outerHTML nor responseXML works in Firefox 2.0 -->
                  var hist = $$("buildHistory");

                  var newhist = document.createElement('div');
                  newhist.innerHTML = rsp.responseText;
                  newhist.headers = hist.headers

                  replace(hist, newhist);
                  fireBuildHistoryChanged();
                }
            });
            }
```
becomes
```


Aytunc Beken

unread,
May 22, 2020, 9:33:45 AM5/22/20
to Jenkins Developers
Hi,

Finally solved the problem with JavaScriptMethod.

For the problem was in Script side.

I had the change the ${instance} to ${it}

var pipelineAsYamlSnippetizer = <st:bind value="${it}" />

Thank you all for the help.
On Tue, May 19, 2020 at 12:27 PM Ullrich Hafner <ullric...@gmail.com> wrote:
The problem with the alternatives is that they have no server counterpart. Or how do you route the requests to the Java model when using jQuery directly?
Am 19.05.2020 um 20:52 schrieb 'Gavin Mogan' via Jenkins Developers <jenkin...@googlegroups.com>:

Ajax.Request is actually prototype, and I strongly recommend not using it, as its incredibly old and has messed with a lot of standard apis.

I recommend using jquery, or the native alternatives (XMLHttpRequest/fetch)

http://youmightnotneedjquery.com/ (search for ajax) has some good examples

On Tue, May 19, 2020 at 11:49 AM Ullrich Hafner <ullric...@gmail.com> wrote:
You can also have a look at some plugins that use the new JS UI components (bootstrap, charts, datatables). All of these plugins use Ajax to populate charts and tables: they also use the techniques described in the wiki and I can confirm that it works! What exactly is not working in your plugin?

The plugins that use these JA Ajax elements are 
- warnings plugin 
- forensics plugin
- autograding plugin

Am 19.05.2020 um 15:58 schrieb Aytunc Beken <aytunc...@gmail.com>:

I will check. Thanks!

On Tuesday, May 19, 2020 at 3:57:27 PM UTC+2, Oleg Nenashev wrote:
Jenkins Build History widget is probably the best example of AJAX usage in Jenkins: 
BR, Oleg

On Tuesday, May 19, 2020 at 3:35:15 PM UTC+2, Aytunc Beken wrote:
Hi,

I am trying to implement Ajax call in UI page. I could only find this page (https://wiki.jenkins.io/display/JENKINS/AJAX+with+JavaScript+proxy) however it did not worked.

I will be glad if anyone can point some help.

- Documentation
- Plugin implemented Ajax
- Plugin implemented Jquery


Thanks a lot.


-- 
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkin...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkin...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkin...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkin...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages