【发布时间】:2012-04-04 22:16:14
【问题描述】:
我是 Grails 的新手,所以这可能是一个愚蠢的问题....但是我正在尝试使用 Grails REST 从 Grails 中的 jquery 客户端获取 json 对象,但我得到了 null。可能是一个小问题,但它对我想要测试的前几个数据流造成了障碍
我的 jquery 调用:
var jsonObjects = [{name: "IPAD", input: "IPAD", program: "IPAD", destination: "IPAD",
priority: "IPAD", userData: "IPAD", email: "IPAD", webCallBackURL: "IPAD", copyToLocal:
"IPAD", scriptPreProcess: "IPAD", deleteSource: "IPAD", moveToSource: "IPAD",
scriptPostProcess: "IPAD", inputImage: "IPAD", leftImage: "IPAD", topImage: "IPAD",
opacityImage: "IPAD", bImageAdAvBlanking: "IPAD"}]
$.ajax({
type: "POST",
url: 'http://localhost:8080/Medusa/jobControlREST/save',
data: {ipad: JSON.stringify(jsonObjects)},
contentType: "application/json; charset=utf-8",
dataType: "json",
beforeSend: function(x) {
if (x && x.overrideMimeType) {
x.overrideMimeType("application/json;charset=UTF-8?");
}
},
success: function() {
alert('hi');
}
});
我的圣杯:
>def save = {
def jsonString = params['ipad'] //returns null
def json = JSON.parse(jsonString) // returns null obviously
println "this is POST call" +json // gets printed but json is null...sign (
}
urlmapping:
"/$controller/$action?/$id?"(parseRequest:true) {
constraints {
action = [GET:"index", POST:"save", PUT:"update", DELETE:"remove"]
}
}
【问题讨论】:
-
您确定您的
data是从客户端正确发送的吗?您是否使用 Firebug 或其他工具检查过您的 AJAX 调用? -
嗨 Aiolos - 你是对的,我尝试使用 chrome 浏览器并且它可以工作,但是同一段代码不适用于 Internet Explorer 8。为什么?我还没有弄明白,但 IE 肯定给了我一个问题。非常感谢您的宝贵时间!