Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/443.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法将角度应用程序中的数据发布到播放!框架_Javascript_Java_Json_Angularjs_Playframework - Fatal编程技术网

Javascript 无法将角度应用程序中的数据发布到播放!框架

Javascript 无法将角度应用程序中的数据发布到播放!框架,javascript,java,json,angularjs,playframework,Javascript,Java,Json,Angularjs,Playframework,我从浏览器调试器中收到以下错误: 在访问控制允许原点标头中找不到原点 但是,我在API中的Global.java文件中设置了头: Global.java @Override public Promise<SimpleResult> call(Http.Context ctx) throws java.lang.Throwable { Promise<SimpleResult> result = this.delegate.call(ctx); Http.R

我从浏览器调试器中收到以下错误:

在访问控制允许原点标头中找不到原点

但是,我在API中的
Global.java
文件中设置了头:

Global.java

@Override
public Promise<SimpleResult> call(Http.Context ctx) throws java.lang.Throwable {
    Promise<SimpleResult> result = this.delegate.call(ctx);
    Http.Response response = ctx.response();
    response.setHeader("Access-Control-Allow-Origin", "*");
    response.setContentType("application/json");
    return result;
}
@BodyParser.Of(BodyParser.Json.class)
public Result insertUser() {
    JsonNode json = request().body().asJson();
    String email = json.findPath("email").asText();
    String username = json.findPath("username").asText();
    String password = json.findPath("password").asText();
    if(email == null || username == null || password == null) {
      return badRequest("Missing parameter[s]");
    } else {
        User user = new User(username, email, false, password, getDate(), getDate());
        repo.insertUser(user);
        return getUserByEmail(email);
    }
}
以下是控制器方法:

UserController.java

@Override
public Promise<SimpleResult> call(Http.Context ctx) throws java.lang.Throwable {
    Promise<SimpleResult> result = this.delegate.call(ctx);
    Http.Response response = ctx.response();
    response.setHeader("Access-Control-Allow-Origin", "*");
    response.setContentType("application/json");
    return result;
}
@BodyParser.Of(BodyParser.Json.class)
public Result insertUser() {
    JsonNode json = request().body().asJson();
    String email = json.findPath("email").asText();
    String username = json.findPath("username").asText();
    String password = json.findPath("password").asText();
    if(email == null || username == null || password == null) {
      return badRequest("Missing parameter[s]");
    } else {
        User user = new User(username, email, false, password, getDate(), getDate());
        repo.insertUser(user);
        return getUserByEmail(email);
    }
}
以下是我的Angular应用程序的API调用:

userapiservice.js

POST        /api/users/insertuser                      @controllers.UserController.insertUser
var factory = {};
var baseUrl = 'http://127.0.0.1:9000/api/users/';

factory.insertUser = function (user) {
  return $http({
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    url: baseUrl + 'insertuser/',
    params: { username: user.username, email: user.email, password: user.password }
  });
};

我有什么遗漏/做错了吗?在几个浏览器上试用过,已经在上面呆了大约一个星期了,我一直在自学,我找到了剧本!文件将。。。好的

首先添加飞行前请求

OPTIONS   /*all                                     controllers.Application.preflight(all)

但是记住

@Override
    public Promise<SimpleResult> call(Http.Context ctx) throws java.lang.Throwable {
        Promise<SimpleResult> result = this.delegate.call(ctx);
        Http.Response response = ctx.response();
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setContentType("application/json");
        return result;
    }
@覆盖
公共承诺调用(Http.Context ctx)抛出java.lang.Throwable{
承诺结果=this.delegate.call(ctx);
Http.Response=ctx.Response();
response.setHeader(“访问控制允许原点“,“*”);
setContentType(“应用程序/json”);
返回结果;
}

内部服务器错误时呼叫不起作用

您是否尝试过处理该错误的goggle?apiYes上的CORS设置错误是的,事实上我是从谷歌那里得到这些CORS设置的,我设置错了什么?确保允许选项请求。我对
play
一无所知,但问题肯定是CORS