javascript - 为什么我的Grails应用程序无法从Angular脚本中获取对象?

标签 javascript json angularjs grails

我正在尝试将对象添加到Grails中的JSON列表中。这是我的Angular代码:
http://pastebin.com/4ypijUMD

还有我的Grails Controller :
http://pastebin.com/skTtVtxv

据我了解,我的angularJS脚本应该发送一个请求,以使用列表中最新成员的信息访问添加 Controller 。

然后,add函数应基于从 Angular 脚本和ta-da传递到 Controller 的参数创建一个新的JSON对象。

但是,什么也没有创建,当我尝试更新我的对象时,我只会得到空对象

list with my update controller:
    def saveList() {
        def newItem = Item.findById(request.JSON.id)
        newItem.name = request.JSON.name
        newItem.type = request.JSON.type
        newItem.priority = request.JSON.priority
        newItem.completed = request.JSON.completed
        newItem.save(flush: true)
        render newItem as JSON
    }

最佳答案

您没有显示进行实际AJAX调用的代码,仅显示了带有保存调用的服务。使用Grails和Angular进行此操作的方式如下所示:

$http.post('http://localhost:8080/test-app/myController/addItem', { json values})
    .success(function(response) {})
    .error(function(response) {});

class MyController {
    def addItem() {}
}

关于javascript - 为什么我的Grails应用程序无法从Angular脚本中获取对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30327774/

相关文章:

javascript - 实时过滤json

JavaScript 将 blob 保存到 localStorage

angularjs - 将 Angular 1 Simple 与 Express JS 一起使用

javascript - AngularJS:$watchCollection 不起作用;抛出错误

用于表单输入的 Javascript switch 语句

javascript - Firebase 仅允许创建者发帖

javascript - 我无法在 Reactjs 中 console.log() JSON 数据?

javascript - 如何查询存储在 mongoDB 数组中的对象

json - 如何在 Ubuntu webhook 命令上设置 webhook 密码?

javascript - Angular js 绑定(bind)不起作用