来自Velocity模板的AJAX调用

时间:2012-02-21 07:26:10

标签: jquery ajax jira velocity jira-plugin

我有一个测试网页,它使用jQuery和AJAX来调用ASMX webservice并返回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调用,那就太棒了。

提前致谢!

1 个答案:

答案 0 :(得分:0)

我通常使用这种代码来做:

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

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

           问题标签使用的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

包含资源