Redmine中使用ajax
其他
2018-08-01 06:17:47
阅读次数: 0
1. view 代码
1
2
3
4
5
6
7
8
9
10
11
12 |
<input class="xc_tags" type="checkbox" name="<%= cboxid %>" id="<%= cboxid %>"
onchange="tagIssue('<%= escape_javascript tagissue_xc_tag_path( {:id => tag.id, :issue_id => @issue.id, :format => 'js'} )%>', this); return false;"/>
<script>
// 一般放在独立的js文件中
function tagIssue(url, elem) {
return $.ajax({
url: url,
type: 'get'
});
}
</script>
|
2. 目标 contorller
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 |
# /xc_tag/1/tagissue/:issue_id
def tagissue
begin
@issue = Issue.find(params[:issue_id])
rescue ActiveRecord::RecordNotFound
#render plain: "no such issue", status: 404
head :no_content
return
end
if @xc_tag.issues.exists?(@issue)
# take off the tag
@xc_tag.issues.delete(@issue)
else
# put the tag on
@xc_tag.issues << @issue
end
respond_to do |format|
format.html
format.js
end
end
|
2.1. 目标js
- views\xc_tags\tagissue.js.erb
1 |
alert("<%= @xc_tag.tagname %>");
|
转载自blog.csdn.net/weixin_42463677/article/details/81178506