来自 Velocity 模板的 AJAX 调用

发布于 2025-01-07 04:41:35 字数 1068 浏览 2 评论 0原文

我有一个测试网页,它使用 jQuery 和 AJAX 调用 ASMX Web 服务并返回 JSON 格式的客户列表。然后返回的数据将填充标签的自动完成列表。在测试环境中一切正常。我现在尝试在 JIRA 中使用相同的代码,以便我可以使用 AJAX 调用将返回的客户列表填充自定义字段,但是 AJAX 调用不起作用。在我的速度模板文件中,我有以下用于 AJAX 调用的代码:

<script>
jQuery("#customfield_10000").autocomplete({
        source: function (request, response) {
            $.ajax({
                type: "POST",
                url: "http://myserver/jiraservice/ajaxservice.asmx/GetCustomers",
                cache: false,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: "{inputValue:\"" + request.term + "\"}",
                success: function (data) {
                    response($.map(data.d, function (item) {
                        return {
                            label: item,
                            value: item
                        }
                    }));
                }
            });
        },
        minLength: 2
});
</script>

如果有人可以指出如何从 Velocity 模板正确执行 AJAX 调用,那就太好了。

提前致谢!

I have a test webpage which uses jQuery and AJAX to call an ASMX webservice and returns a list of customers in JSON format. The returned data then populates an autocomplete list for an tag. In the test environment everything works perfectly. I am now trying to get the same code working in JIRA so i can populate a customfield with the list of customers the AJAX call will return, however the AJAX call doesn't work. In my velocity template file i have the following code for the AJAX call:

<script>
jQuery("#customfield_10000").autocomplete({
        source: function (request, response) {
            $.ajax({
                type: "POST",
                url: "http://myserver/jiraservice/ajaxservice.asmx/GetCustomers",
                cache: false,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: "{inputValue:\"" + request.term + "\"}",
                success: function (data) {
                    response($.map(data.d, function (item) {
                        return {
                            label: item,
                            value: item
                        }
                    }));
                }
            });
        },
        minLength: 2
});
</script>

If someone could please point out how to properly perform an AJAX call from a Velocity template, that would be great.

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忘羡 2025-01-14 04:41:35

我通常使用这种代码:

        AJS.$.get('/rest/api/latest/issue/' + release, {}, function(data) {
            var fields = data["fields"];
            var summary = fields["summary"]["value"];

然后确保 atlassian-plugin.xml 中存在 AJS

问题选项卡使用的 JavaScript 和 CSS 文件。

<dependency>com.atlassian.auiplugin:ajs</dependency>
<dependency>jira.webresources:jira-global</dependency>

<resource name="issuetabs.js" type="download" location="js/issuetabs.js" />
<resource name="issuetabs.css" type="download" location="css/issuetabs.css" />

并确保使用 WebResourceManager 包含资源

I usually do it using this kind of code:

        AJS.$.get('/rest/api/latest/issue/' + release, {}, function(data) {
            var fields = data["fields"];
            var summary = fields["summary"]["value"];

and then make sure that AJS exists with this in atlassian-plugin.xml

JavaScript and CSS files used by Issue Tabs.

<dependency>com.atlassian.auiplugin:ajs</dependency>
<dependency>jira.webresources:jira-global</dependency>

<resource name="issuetabs.js" type="download" location="js/issuetabs.js" />
<resource name="issuetabs.css" type="download" location="css/issuetabs.css" />

and make sure that resource gets included using a WebResourceManager

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文