[英]How to use remoteFunction inside a .js file in grails
我有一个要求,就是每当我单击一天(以日历的形式)时,都需要弹出一个带有详细信息的弹出窗口。 我需要触发一个动作/控制器来获取详细信息。 我的event.click在我的.js文件中。 我一直在尝试在完整日历jquery中使用remoteFunction。 但是grails无法识别remoteFunction调用,并且我的屏幕出现了问题(因为.js模板不可用)。 请尽可能帮我
$(calId[calNo]).fullCalendar({
header : {
left : ' ',
center : 'title',
right : ' '
},
defaultView: 'month',
selectable: true,
weekMode : 'variable',
eventColor : 'white',
editable : false,
year : eventYr,
month : calNo,
events : allocData,
dayRender: function (event, element, view) {
for (i = 0, l = holidayData.length; i < l; i++) {
var dateString = holidayData[i].substring(0,10);
view.element.find('.fc-day[data-date="' + dateString + '"]').css('background-color', '#FF9999');
view.element.find('.fc-other-month').css('background-color', '#FFFFFF');
}
},
eventRender: function(event, element, view)
{
if(event.start.getMonth() !== view.start.getMonth()) { return false; }
},
eventClick: function(event) {
var selectedDate = String(event.start);
var newData = ${remoteFunction(controller: 'PreSchedule', action: 'calProcess')};
alert(newData);
$('#dateAllocation #selectedDate').text(String(selectedDate).substring(0,10) + ' ,' + String(selectedDate).substring(28,33));
$('#dateAllocation').modal('show');
},
select: function(date) {
var selectedDate = date;
$('#dateAllocation #selectedDate').text(String(selectedDate).substring(0,10) + ' ,' + String(selectedDate).substring(28,33));
$('#dateAllocation').modal('show');
}
});
可能是我在混合服务器端代码和客户端代码,弄混了基础知识。 提前致谢。
我没有使用remotefunction,而是尝试使用jquery.ajax / createLink。 但是网址没有得到解析。
$("#link").click(function(event){
alert('link');
event.preventDefault();
date = '1985-01-01';
$.ajax({
url:'${createLink(controller:"Student",action:"checkLink")}',
// url:'/checkLink',
dataType: 'json',
type: 'POST',
//data: date,
success: function() {
console.log("The returned data is: ");
// show your modal, or do whatever you want.
}
});
我可以在浏览器开发人员工具中看到错误
加载资源失败:服务器响应状态为404(未找到)
// smsFrontEnd / student / $%7BcreateLink(controller:%22Student%22,action:%22checkLink%22)%7D
如果可能的话,请帮帮我
我认为您无法在.js文件中使用grails ajax标签库。
但是,不建议您添加这些taglib,并且无论如何都不应使用它们。 由于这不是一个好习惯
http://grails.org/doc/latest/ref/Tags/remoteFunction.html
The formFunction tag and other Ajax related tags have been deprecated and will be removed from a future version of Grails. Applications may provide their own Ajax tags and/or Javascript plugins may provide Ajax tags of their own.
http://en.wikipedia.org/wiki/Unobtrusive_JavaScript
我认为您最好使用jquery.Ajax代替那里的remoteFunction。
如果您的控制器正在返回JSON数据,则可以按以下方式获取和使用它:
代替:
var newData = ${remoteFunction(controller: 'PreSchedule', action: 'calProcess')};
alert(newData);
使用jQuery $.ajax
方法:
$.ajax({
dataType: 'json',
url: '${createLink(controller: 'preSechedule', action: 'callProcess')}',
data: {}, // no parameters
success: function(data) {
window.alert("The returned data is: "+data);
// show your modal, or do whatever you want.
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.