Jquery 在gsp中解析json并更新内容
我在grails控制器中有这样一个方法,我在gsp的jquery中调用它Jquery 在gsp中解析json并更新内容,jquery,json,grails,Jquery,Json,Grails,我在grails控制器中有这样一个方法,我在gsp的jquery中调用它 def ajaxStatus(){ CustomerInterest customerInterestInstance=CustomerInterest.get(params.ciId) InterestStatus status=InterestStatus.valueOf(params.status) customerInterestInstance.status=status
def ajaxStatus(){
CustomerInterest customerInterestInstance=CustomerInterest.get(params.ciId)
InterestStatus status=InterestStatus.valueOf(params.status)
customerInterestInstance.status=status
customerInterestInstance.save(flush:true,failOnError:true)
render customerInterestInstance as JSON
}
问题:
我想解析gsp中的customerInterestInstance并更新gsp中的内容我该怎么做
这个
我要更新的代码是
<span class="staFloat">
${ci?.status}
<button onclick="openDialog(${ci?.id})"class=btn id="btn">
<img id="status_edit"src="${resource(dir:'images/skin',file:'edit.png')}"/>
</button>
</span>
如果您想更新div,那么可以使用jQuery的html。如果你想更新${ci?.status},那么把它放在一个span中,给这个span一个id,然后使用html。我知道这一点,但在使用html之前,我必须解析json。。。?正确与否?您在ajax中的响应变量中获得了json响应。在那里,您可以轻松获得customerInterestInstance的任何属性,如response.Status非常感谢@user1690588
"Change": function(){
var st = $('[name="st"]:checked').val();
$.ajax({
url: "${createLink(controller: 'Employee', action: 'ajaxStatus')}",
data: ({
ciId:ciId,
status:st
}),
dataType:"JSON",
success: function(response) {
// call 'refresh' method to load new content
alert("changed")
},
error: function(){
alert("Select options");
}
});
$(this).dialog('close');
},
Cancel : function() {
$(this).dialog('close');
}
},