I have one g:select with an onchange event that fires a remoteFunction that is calling the request method as well, however, the callback JS function isn’t been calling.
This is the g:select:
<g:select id="categories"
name="categories"
from="${Category.findAll('from Category where master is null')}"
noSelection="['':'- Selecione -']" optionKey="id" optionValue="description"
onchange="${remoteFunction(
controller: 'event',
action: 'subCategoriesJSON',
params:'\'id=\' + escape(this.value)',
onSuccess: 'updateSubs(data,textStatus)'
)}"
/>
The subCategoriesJSON is called as well, but there is no way to remoteFunction calls after that the updateSubs function. My page is rendering the scope of the function correctly on the head tag.
This is the function:
<script type="text/javascript">
$(document).ready(function() {
function updateSubs(data, textStatus) {
alert('call me!!!');
var subs = eval("(" + e.responseText + ")");
if (subs) {
$("span#saida").html(subs);
}
}
});
</script>
Any clue will be very welcome. Thanks a lot!
It looks like
updateSubsis defined as a local function, which means it isn’t accessible from the global scope. Basically move yourupdateSubsfunction out of the$(document).ready()– it doesn’t need to be there really as there is no need for your code to wait until the dom is ready before defining that function.That should solve your main problem, however you’ll have to edit your code further as you are trying to access
e.responseTextwhen you have no access to a variable namede– this will just trip an error until it is fixed. I’ve commented the problem code for now.Anyway, once
updateSubsis in the global scope theonSuccesshandler should be able to access it.For further information about function scope, have a read about Nested functions and closures.