Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/462.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 检索不使用AngularJS和GSON的JSON_Javascript_Json_Angularjs_Resteasy - Fatal编程技术网

Javascript 检索不使用AngularJS和GSON的JSON

Javascript 检索不使用AngularJS和GSON的JSON,javascript,json,angularjs,resteasy,Javascript,Json,Angularjs,Resteasy,我有一个RESTapi,使用以下方法: @Path("/banksummary") public class BankSummaryRestService { Database db = new DatabaseAccessOutput(); @GET @Path("/") public String printMessage() throws Exception { Summary result; try {

我有一个RESTapi,使用以下方法:

@Path("/banksummary")
public class BankSummaryRestService {
    Database db = new DatabaseAccessOutput();

    @GET
    @Path("/")
    public String printMessage() throws Exception {
        Summary result;

        try {
            result = db.getBankSummary();

        }
        catch (Exception e) {
            throw e;
        }

        Gson gson = new Gson();
        String json = gson.toJson(result);


        return json;
    }
}
当我转到
localhost:8080/html5/api/1.0/banksummary
时,我看到了输出

在我的AngularJS项目中,我有以下代码: 在service.js中:

dashboardAPI.getBankSummary = function() {
        return $http(
        {
            method: 'GET',
            url: 'localhost:8080/html5/api/1.0/banksummary'
        }
        );
    }
在控制器中:

dashboardAPIService.getBankSummary().success(function (response) {
        $scope.summary = response;
    });
当我使用本地json文件时,它工作正常,但现在我使用RESTapi的URL(本地文件必须被RESTapi替换),我得到以下错误:

XMLHttpRequest cannot load localhost:8080/html5/api/1.0/banksummary. Cross origin requests are only supported for HTTP. angular.min.js:76
Error: A network error occurred.

有人知道我做错了什么吗?

您需要在URL中指定协议(在本例中为http):

dashboardAPI.getBankSummary = function() {
    return $http(
    {
        method: 'GET',
        url: 'http://localhost:8080/html5/api/1.0/banksummary'
    }
    );
}

是的,这确实是解决办法。