Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Ajax request in Grails

How to use jQuery to make Ajax request in Grails pages?

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'.

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.

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.

like image 474
Himanshu Yadav Avatar asked Dec 12 '22 02:12

Himanshu Yadav


1 Answers

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() {
    }
});
like image 156
Luis Muñiz Avatar answered Dec 27 '22 11:12

Luis Muñiz