【发布时间】:2014-01-07 07:33:00
【问题描述】:
我的代码 sn-p 是:
$('#PostCode').autocomplete({
source: function (request, response) {
$.ajax({
url: "${createLink(controller:'postcode',action:'getValidPostcodeValues')}",
dataType: "json",
success: function( data ) {
response( $.map( data, function( item ) {
return {
id: item.id,
value: item.name
}
}));
}
});
},
minLength: 1,
select: function (event, ui) {
$('#PostCodeHidden').val(ui.item.id);
}
});
但是它不起作用。我使用 chrome web 工具来跟踪 ajax 调用 url 类似于
GET http://localhost:8080/edp-grails/xxx/xxx/$%7BcreateLink(controller:'postcode',action:'getValidPostcodeValues')%7D 404 (Not Found)
为什么 grails 不能将 createlink 解释为实际的 url?
【问题讨论】:
-
你在哪里有这个代码?
.gsp或.js文件? -
同意伊戈尔。您所说的表明
${}不是由常规代码解释的,而是被视为字符串。${createLink...}必须在 GSP 文件中 -
对。应该在 gsp 文件中。谢谢