Grails render template or JSON? -
Grails render template or JSON? -
i have controller uploads , processes file. afterwards, wish render processing result in modal div. wanted know best way results controller modal div on gsp. thought template didn't know how specify target div template should because template wouldn't rendered button click target template render set attribute, done on timed basis (i.e. when file done uploading). other way send json controller don't know how intercept json @ right time because still don't quite understand timings of info flow between gsp , controller. know how send json how alert gsp "hey, json ready modal that's go up." here pseoducode of trying done.
controller:
upload() { // process file , store results in 3 integers // int1 = result1 // int2 = result2 // int3 = result3 // send 3 numbers gsp }
now best way these 3 numbers gsp displayed on modal dialog go this:
<div id="fileuploadresultsmodal"> results: ${int1}, ${int2}, ${int3} </div>
here js associated ajax upload function:
$("#chsefile").upload("${createlink(controller: 'customer', action: 'upload',)}", {datatypegrp: parseint(getcheckedvalue(document.getelementsbyname('datatypegrp'))), filetypegrp: parseint(getcheckedvalue(document.getelementsbyname('filetypegrp')))}, function(success) { $("#cancel1").trigger("click"); settimeout(function(){ $("#summary").trigger("click"); }, 250); displaysuccess(data); }, function(prog, value) { console.log(value); $("#prog").val(value); if (value == 100) { $("#prog").hide(); $("#progressbar").html("uploading , processing. please wait..."); } });
but right js complains 'data' not defined. 'data' meant json coming controller.
thanks
you can render them json:
render( [ int1:111, int2:222, int3:333 ] json )
or html-string
render "<div id=\"fileuploadresultsmodal\">results:${int1}, ${int2}, ${int3}</div>"
or utilize template
render template:'/yourcontroller/templatename', model:[ int1:111, int2:222, int3:333 ]
or taglib
render g.yourresulttag( int1:111, int2:222, int3:333 )
for tiny bit of information, performance not of concern. it's rather matter of taste, or more appropriate client.
if later json-biased, utilize json-rendering. if has mix of json , html, utilize others.
json grails
Comments
Post a Comment