首先,抱歉我的英语不好,我是法语。
这里的问题:
我有一个看起来像这样的模板:
<p>
<strong>Whas this answer usefull ?</strong>
<g:remoteLink action="niceAnswer"
class="btn rate-reply"
update="comment-${ comment.id }"
params="${ [commentId: comment.id, nice: true, productId: productId] }">
Yes
</g:remoteLink>
<g:remoteLink action="niceAnswer"
class="btn rate-reply"
update="comment-${ comment.id }"
params="${ [commentId: comment.id, productId: productId] }">
No
</g:remoteLink>
这里是用于重新加载片段页面的GSP:
<div class="rating" id="comment-${ comment.id }">
<g:render template="affRating" model="${ [comment: comment, productId: product.id] }" />
</div>
这是生成的javascript(通过firebug查看):
<a class="btn rate-reply" action="niceAnswer" onclick="jQuery.ajax({type:'POST',data:{'commentId': '723','nice': 'true','productId': '872'}, url:'/macsf-fronts/action/commentaire/reponse-utile',success:function(data,textStatus){jQuery('#comment-723').html(data);},error:function(XMLHttpRequest,textStatus,errorThrown){}});return false;" href="/macsf-fronts/action/commentaire/reponse-utile?commentId=723&nice=true&productId=872"> Yes </a>
这是执行此操作的 Controller 代码:
def niceAnswer() {
def comment = DocCommentaireSite.get(params.commentId)
if (comment && session["comment_${comment.id}"] == null) {
if (params.nice) {
comment.nbYesReponseUtile++
}
comment.nbReponseUtileVote++
session["comment_${comment.id}"] = comment.id
comment.save()
}
def product = DocProduitSite.get params.productId
if (request.xhr) {
log.debug "niceAnswer : All is good"
render template: 'affRating',
model: [comment: comment, productId: params.productId]
} else {
log.debug "niceAnswer : bad behaviour"
def slugMap = referenceService.getSlugAndParentSlug(product)
log.info "slugMap : ${slugMap}"
redirect controller: 'frontRequest', action: 'index', params: [slug: slugMap.slug, parentSlug: slugMap.parentSlug]
}
log.debug "niceAnswer : wtf ?!"
}
唯一呈现的日志是“一切都很好”。
但是每次在响应中重新加载整个页面时,我真的不明白为什么。
提前致谢,
ite
请您参考如下方法:
每当我发生这种情况时,都是因为我的GSP上没有这个:
<g:javascript library="jquery" />




