如何使用 jQuery 在 Grails 页面中发出 Ajax 请求?
如何设置 URL 来命中 Grails Controller 上的方法?假设 Controller :“airport”,操作:“getJson”,操作的输入是“iata”。
我可以将静态网址设置为http://localhost:8080/trip/airport/getJson
,但无法弄清楚如何专门传递iata的输入。
我对 Grails 相当陌生,并且正在关注 IBM 的“掌握 Grails”教程系列。请给我推荐一些有关在 Grails 中使用 jQuery 的好教程。
最佳答案
在jquery中使用$.ajax方法
$.ajax({
url:"${g.createLink(controller:'airport',action:'getJson')}",
dataType: 'json',
data: {
iata: '.............',
},
success: function(data) {
alert(data)
},
error: function(request, status, error) {
alert(error)
},
complete: function() {
}
});
关于ajax - Grails 中的 jQuery Ajax 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10431049/