javascript - Execute controller function in Grails via Ajax -


i novice ajax in grails. want try execute controller method gsp-code ajax.

this part of gsp-code:

<g:select   optionkey="id" name="region.id" id="region" from="${region}" noselection="[null:' ']"   onchange="categorychanged(this.value);" ></g:select> <div>   <b>sub-category: </b>   <span id="subcontainer"></span> </div>                 <script>                     function categorychanged(regionid) {                         $.ajax({type:'post',data:'regionid='+regionid, url:'restorator/region/categorychanged',success:function(data,textstatus){jquery('#subcontainer').html(data);},error:function(xmlhttprequest,textstatus,errorthrown){}});                     }                 </script> 

in url parameter of $ajax call: restorator package, region controller in , categorychanged action.

this controller:

class regioncontroller {      def ajaxgetcities = {         println "hello"         def region = region.get(params.id)         render region?.cities json     }      def categorychanged(long regionid) {         println "test"         region region = region.get(regionid)         def subcategories = []         if ( region != null ) {             subcategories = city.findallbyregion(region, [order:'cityname'])         }         render g.select(id:'subcategory', name:'subcategory.id',             from:subcategories, optionkey:'id', noselection:[null:' ']         )     } } 

in head part i've added <g:javascript library='jquery' /> when try change option in select tag don't see output console, should shown theprintln "test" line inside controller. means controlloer function never called, doing wrong ? how make sure function call happens ?

right click on page,inspect element , see if there errors in console.

also, should specify url way:

url: '${createlink(controller: 'region', action: 'categorychanged')}', 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -