javascript - withFormat closure is not sending response based on ACCEPT header -
i'm trying withformat closure in grails. i've got following in action:
if (myinstance.save(flush: true)) { withformat { html {redirect(action: "list") } js {render "alert('came here')"} } } as understand withformat closure: if accept header text/javascript render alert , if ['text/html','application/xhtml+xml'] redirect list action. however, in case rendering list action.
i'm using rest console in chrome , here details of request header:
accept: text/javascript content-type: application/json connection: keep-alive origin: chrome-extension: //rest-console-id user-agent: mozilla/5.0 (macintosh; intel mac os x 10_8_2) applewebkit/537.31 (khtml, gecko) chrome/26.0.1410.65 safari/537.31 and here response headers:
status code: 200 date: fri, 10 may 2013 14:45:18 gmt server: apache-coyote/1.1 transfer-encoding: chunked content-language: en-us content-type: text/html;charset=utf-8 the response body coming html whereas i'm expecting js
the mime types seem correct in config.groovy
grails.mime.types = [ all: '*/*', atom: 'application/atom+xml', css: 'text/css', csv: 'text/csv', form: 'application/x-www-form-urlencoded', html: ['text/html','application/xhtml+xml'], js: 'text/javascript', json: ['application/json', 'text/json'], multipartform: 'multipart/form-data', rss: 'application/rss+xml', text: 'text/plain', xml: ['text/xml', 'application/xml'] ] what doing wrong here??
after testing found out whichever closure comes first taking precedence. if have:
withformat { js {render "alert('came here')"} html {redirect(action: "list") } } then js being rendered if testing application browser...
grails.mime.use.accept.header = true setting required in config.groovy. have set?
refer bottom of withformat page.
Comments
Post a Comment