My first question here.
Has anybody had any problem with using shorthand functions for ajax requests?
This works:
('#book').typeahead({
source: function(typeahead, query){
return $.ajax({
url: "/book/autocompleteBooks",
type: "GET",
dataType: "JSON",
data: {queryString: query},
success: function(results){
typeahead.process(results);
}
});
},
property: "title",
onselect: onSelectBook
});
But none of these two works:
('#book').typeahead({
source: function(typeahead, query){
return $.get({
url: "/book/autocompleteBooks",
dataType: "JSON",
data: {queryString: query},
success: function(results){
typeahead.process(results);
}
});
},
property: "title",
onselect: onSelectBook
});
('#book').typeahead({
source: function(typeahead, query){
return $.getJSON({
url: "/book/autocompleteBooks",
data: {queryString: query},
success: function(results){
typeahead.process(results);
}
});
},
property : "title",
onselect: onSelectBook
});
The other thing is that replacing url with createLink does not work also.
url: "/book/autocompleteBooks"
url: "${createLink(controller: 'book', action: 'autocompleteBooks')}"
I’d rather use shorthand functions to make to code to be simplier to read and basically for aesthetics 🙂
Structure of
$.get()is like:and
$.getJSON()is:Read more about $.get() and $.getJSON()