我正在尝试创建$ http get请求以获取由我的Web服务生成的一些json数据,但它返回null错误。但是,当我使用此示例网址代替时,$ http请求可以正常工作(它也返回json字符串)
这是我的角度代码:
angular.module('ionicApp', ['ionic'])
.controller('ListCtrl', function ($scope, $http) {
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
$http.get("http://localhost:8080/InventoryCtrl_Service/webresources/IVC_Service/GetUserList")
.then(function(response) {
console.log("success ");
},
function(response) {
console.log("Error : " + response.data + " Status : " + response.status);
}
});
这是我的网络服务代码:
@GET
@Path("/GetUserList")
@Produces("application/json")
public Response GetUserList() throws SQLException {
net.sf.json.JSONObject json = new net.sf.json.JSONObject();
JSONObject obj1 = new JSONObject();
JSONObject obj2 = new JSONObject();
JSONObject outerObject = new JSONObject();
JSONArray arr = new JSONArray();
obj1.put("Name", "Sara");
obj2.put("Name","David");
arr.add(obj1);
arr.add(obj2);
outerObject.put("records", arr);
return Response.status(200).entity(outerObject.toString()).build();
}
当我运行上面的代码时,它将返回json字符串,如下所示:
{"records":[{"Name":"Sara"},{"Name":"David"}]}
控制台日志返回以下内容:
Error : null Status : 0
空错误是什么意思?还是我返回json字符串有什么问题吗?
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句