Grails 中的 jQuery Ajax 请求 [英] jQuery Ajax request in Grails
问题描述
如何在 Grails 页面中使用 jQuery 进行 Ajax 请求?
How to use jQuery to make Ajax request in Grails pages?
如何在 Grails 控制器上设置 URL 命中方法?假设控制器:'机场',动作:'getJson',动作的输入是'iata'.
How to setup a URL hitting a method on Grails Controller? Let's say controller:'airport', action:'getJson' and input to the action is 'iata'.
我可以将静态 url 设置为 http://localhost:8080/trip/airport/getJson
但无法弄清楚如何专门为 iata 传递输入.
I am able to set static url as http://localhost:8080/trip/airport/getJson
but not able to figure out how to pass input for iata specifically.
我对 Grails 还很陌生,正在学习 IBM 的掌握 Grails"教程系列.请给我推荐一些关于在 Grails 中使用 jQuery 的好教程.
I am fairly new to Grails and following IBM's 'Mastering the Grails' tutorial series. Do suggest me some good tutorial on using jQuery with Grails.
推荐答案
在jquery中使用$.ajax方法
use the $.ajax method in jquery
$.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() {
}
});
这篇关于Grails 中的 jQuery Ajax 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!