gpt4 book ai didi

ajax - grails3 Ajax请求在渲染为JSON后中断

转载 作者:行者123 更新时间:2023-12-02 14:40:45 25 4
gpt4 key购买 nike

我目前正在使用grails安全插件将应用程序从grails 2.4.4迁移到grails 3.1.5

我正在使用grails ajax request plugin进行ajax调用,但是在调用ajax之后收到此错误。

我返回的是POJO的ArrayList,而不是从API调用获得的POGO对象

state/stateforcountry - parameters:
countryName: Ghana
Stacktrace follows:
java.lang.reflect.InvocationTargetException: null
at grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter.doFilter(GrailsAnonymousAuthenticationFilter.groovy:53)
at grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter.doFilter(MutableLogoutFilter.groovy:62)
at grails.plugin.springsecurity.web.SecurityRequestHolderFilter.doFilter(SecurityRequestHolderFilter.groovy:58)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException: null
at grails.converters.JSON.value(JSON.java:180)
at grails.converters.JSON.convertAnother(JSON.java:144)
at grails.converters.JSON.value(JSON.java:184)
at grails.converters.JSON.render(JSON.java:119)
at grails.converters.JSON.render(JSON.java:132)
at grails.artefact.controller.support.ResponseRenderer$Trait$Helper.render(ResponseRenderer.groovy:191)
at smartinsure.admin.StateController$_stateForCountry_closure1$_closure2.doCall(StateController.groovy:29)
at grails.artefact.Controller$Trait$Helper.withFormat(Controller.groovy:92)
at smartinsure.admin.StateController.stateForCountry(StateController.groovy:28)
... 6 common frames omitted

有人可以帮忙吗?

最佳答案

我终于通过使用来自groovy.json包的另一个groovy转换API解决了它

def getUsers(){
def users = userService.getAllUsers();
render JsonOutput.toJson(users);
}

与此 render users as JSON相反。 JsonOutput在 groovy.json包中或更佳
withFormat {
html { render view:"edit", model:users}
json { render JsonOutput.toJson(users)}
xml { render users as XML}
}

关于ajax - grails3 Ajax请求在渲染为JSON后中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37114427/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com