首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法将数据从cline发送到服务器

无法将数据从cline发送到服务器
EN

Stack Overflow用户
提问于 2017-01-21 03:00:18
回答 1查看 66关注 0票数 0

我尝试从我的js调用我的java后端。

angular js (http://localhost:8082/dev/index.html#/):

代码语言:javascript
复制
self.submit = function() {
  console.log("in voice prompt component - submit");
  console.log(self.voice);
  $http.put('localhost:8082/api/Voices/updateVoice', self.voice).then(
    function successCallback(response) {
      self.voices = response.data;
    },
    function errorCallback(response) {
      // called asynchronously if an error occurs
      // or server returns response with an error status.
      console.log(response); 
    });
}

java (应该响应localhost:8082/api/Voices/updateVoice

代码语言:javascript
复制
@Path("/Voices")
public class VoicesOperation {

...

    @Path("/updateVoice")
    @PUT
    @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
    public void updateVoice(VoiceBl voice) throws Exception {

        fillVoicesSnapshot();

我得到了这个js异常:

代码语言:javascript
复制
TypeError: 'caller' and 'arguments' are restricted function properties and cannot be accessed in this context.
    at Function.remoteFunction (<anonymous>:3:14)
    at errorCallback (http://localhost:3002/public/js/components/voice-form-component.js:54:29)
    at http://localhost:3002/bower_components/angular/angular.min.js:133:460
    at m.$eval (http://localhost:3002/bower_components/angular/angular.min.js:147:313)
    at m.$digest (http://localhost:3002/bower_components/angular/angular.min.js:144:421)
    at m.$apply (http://localhost:3002/bower_components/angular/angular.min.js:148:78)
    at HTMLButtonElement.<anonymous> (http://localhost:3002/bower_components/angular/angular.min.js:282:247)
    at cg (http://localhost:3002/bower_components/angular/angular.min.js:38:299)
    at HTMLButtonElement.d (http://localhost:3002/bower_components/angular/angular.min.js:38:246)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-01-21 13:41:02

问题出在你的资源文件上,你没有发送任何你正在使用的东西。如果你正在发送一个响应,那么你的返回类型应该是Response,而且你也需要消费。

代码语言:javascript
复制
@Path("/Voices")
public class VoicesOperation {

...

    @Path("/updateVoice")
    @PUT
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
    public Response updateVoice(VoiceBl voice) throws Exception {
        Voice voice = fillVoicesSnapshot();
        return Response.status(Status.CREATED)
                       .entity(voice)
                       .build();
    }
}

或者,如果你发送的是语音类型,那么你的返回类型应该是语音。

代码语言:javascript
复制
@Path("/Voices")
public class VoicesOperation {

...

    @Path("/updateVoice")
    @PUT
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
    public Voice updateVoice(VoiceBl voice) throws Exception {

        return fillVoicesSnapshot();
    } 
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41770637

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档