我有控制器方法,它返回json数据,没有安全检查逻辑.
def getJsonData(){
// return json
}
Run Code Online (Sandbox Code Playgroud)
我正在从另一台服务器(跨域)的php页面做ajax请求.
$.ajax({
type: "GET",
url: "http://localhost:8080/training/getJsonData",
data: { ListID: '1'},
dataType: "jsonp",
success: function(data) {
alert('Hi'+data);
$("#success").html(data);
}
});
Run Code Online (Sandbox Code Playgroud)
数据不是来自服务器,只有在用户登录到应用服务器时才有效.如何在不检查grails登录的情况下提供这些请求.
我有一个从Groovy的HTTPBuilder返回的JSON对象.JSON包含一些表示为JSONNull对象的空值.问题是当我尝试在响应中渲染JSON时,我在尝试渲染JSONNull时出现错误.我得到的回复只是部分呈现的.我希望它呈现为"null".我该怎么做呢?
码:
render(contentType: "text/json") {
listOfJSONObjectsThatIncludeJSONNulls
}
Run Code Online (Sandbox Code Playgroud)
错误:
| Error 2013-09-17 11:33:56,965 [http-bio-8080-exec-4] ERROR errors.GrailsExceptionResolver - JSONException occurred when processing request: [GET] /my/action
Object is null. Stacktrace follows:
Message: Object is null
Line | Method
->> 69 | isEmpty in net.sf.json.JSONNull
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 199 | …Run Code Online (Sandbox Code Playgroud)