无法通过AJAX将数据发布到Grails中的控制器动作

时间:2014-04-28 07:34:53

标签: javascript jquery ajax grails

这是我发布的JavaScript

$.ajax( { type: "POST", dataType: "JSON", url: '${createLink(controller: "customer", action: "updateCheck")}', data: 'this is parameter', success: function(answer){ console.log(answer); } } )

这是我的控制器:

def updateCheck(){ def parameters = params print(parameters) log.error(parameters) }

我想通过客户端的AJAX调用将数据发布到服务器。但我无法做到以下错误

POST http://loscalhost.hasToUseThis:9091/qbx-web/customer/$%7BcreateLink(controller:%20%22customer%22,%20action:%20%22updateCheck%22)%7D 404 (Not Found)

2 个答案:

答案 0 :(得分:3)

我认为这是因为您将'${createLink(controller: "customer", action: "updateCheck")}'括在了“硬”中。引号。如果您使用双引号,则会正确评估${create...}

请改为尝试:

$.ajax({ 
    type: "POST", 
    dataType: "JSON", 
    url: "${createLink(controller: 'customer', action: 'updateCheck')}", 
    data: 'this is parameter', 
    success: function(answer) { console.log(answer); } 
});

答案 1 :(得分:1)

试试这个

$.ajax({
    type: "POST",
    dataType: "JSON",
    url: '${createLink(controller: "customer", action: "updateCheck")}',
    data: {params:'this is params'},
    success: function(answer){
        console.log(answer);
    }
});