Unable to print the content of array of objects in Grails

Saturday, July 5, 2014

DOMAIN CLASS



package marchmock2

class Pgtyp {
Date date_hour
String mv
String pagetype
Integer visits
Integer visits_ly
Integer visits_lw
String time_period
String platform
String device
String browser


static mapping = {
table "pgtyp"
version false
date_hour column: "date_hour"
mv column: "mv"
pagetype column: "pagetype"
visits column: "visits"
visits_ly column:"visits_ly"
visits_lw column:"visits_lw"
time_period column:"time_period"
platform column:"platform"
device column:"device"
browser column:"browser"
}

static constraints = {
}
}


CONTROLLER



package marchmock2
import grails.converters.*
import groovy.sql.Sql


class PgtypController {



def ajaxGetMv = {
def pgtyp = Pgtyp.executeQuery("select p.visits from Pgtyp p where p.mv = ?",["params.id"])

render pgtyp as JSON
}

def index() {

}

}


GSP



<html>
<head>
<g:javascript src="jquery-1.10.2.min.js"/>
<g:javascript src="prototype.js"/>
</head>
<body>
<form>
<g:select from="['AFFILIATES', 'SEO', 'SEM','DISPLAYADS']" name="mv"
onchange="${remoteFunction(
controller:'Pgtyp',
action:'ajaxGetMv',
params:'\'id=\' + escape(this.value)',
onSuccess: 'printpgtyp(data)')}"
></g:select>
</form>
<script>
function printpgtyp(data)
{
console.log(data)

}
</script>
</body>
</html>


I am expecting an array of objects to be printed to the console.However, I am getting the following output in my console:



[each: function, eachSlice: function, all: function, any: function, collect: function…]


Is there anything wrong with the way I am printing it or is it because the value from my GSP is not getting posted to the Controller, somehow?







http://ift.tt/1xvb9Zm