gpt4 book ai didi

jquery - 在 Grails REST 中使用 params 获取 JSON 对象

转载 作者:行者123 更新时间:2023-12-01 06:02:22 25 4
gpt4 key购买 nike

我是 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');
}
});

我的 chalice :

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"]
}
}

最佳答案

使用这个:

def jsonObject=request.JSON

关于jquery - 在 Grails REST 中使用 params 获取 JSON 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10020040/

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