Remotefunction not working

谁说我不能喝 提交于 2020-01-05 09:22:43

问题


Below is my Pgtyp.groovy (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 = {
   }
}

This is how my controller looks like:

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

class PgtypController {

   def ajaxGetMv = {
      def pgtyp = Pgtyp.get(params.id)
      render pgtyp as JSON
   }

   def index() { 
   }
}

And finally, this is my 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>
      <g:javascript>
         function printpgtyp(data) {
            console.log(data)
         }
      </g:javascript>
   </body>
</html>

When I run my app, I get a dropdown and on selecting any option from it I get an error saying:

POST http://localhost:8080/marchmock2/pgtyp/ajaxGetMv 500 (Internal Server Error) 

What do I do with it? Is there any error in the way I'm writing it or have I misunderstood anything? Any help would be appreciated.

UPDATE

|
2014-07-04 16:37:23,149 [http-bio-8080-exec-10] ERROR [/marchmock2].[gsp]  - Servlet.service() for servlet   [gsp] in context with path [/marchmock2] threw exception
Message: It looks like you are missing some calls to the r:layoutResources tag. After rendering your page the       following have not been rendered: [defer]
Line | Method
->> 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    744 | run . . . in java.lang.Thread

UPDATE2

Following an answer on stackoverflow, I changed to and the error mentioned in first UPDATE is gone. However, when I select 'SEO' from the dropdown, I get the following error

TypeMismatchException occurred when processing request: [POST] /marchmock2/pgtyp/ajaxGetMv - parameters:
id: SEO
Provided id of the wrong type for class marchmock2.Pgtyp. Expected: class java.lang.Long, got class     java.lang.String. Stacktrace follows:
Message: Provided id of the wrong type for class marchmock2.Pgtyp. Expected: class java.lang.Long, got class      java.lang.String 

来源:https://stackoverflow.com/questions/24572811/remotefunction-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!