我需要通过身份证并得到相关的问题。错误消息- POST http://localhost:51949/API.asmx/GetAllQuestions/0 - 500 (内部服务器错误)
web服务可以正常工作,因为我已经签入了C#代码的其他部分。现在,试着从天使那里访问它。这条路对吗?
app.js:
var app = angular.module('virtualApp', []);controller.js:
app.controller("virtualController", function ($scope, DataFactory) {
$scope.categories=[];
$scope.GetAllQuestions = function (categoryId) {
DataFactory.GetAllQuestions(categoryId)
.success(function (data) {
$scope.categories = data;
})
.error(function (error) {
alert(error.message);
});
}
$scope.GetAllQuestions(0); //to fire at page load
});services.js: 编辑
app.factory("DataFactory",function ($http) {
var urlBase = "http://localhost:51949/API.asmx/";
var dataFactory = {};
dataFactory.GetAllQuestionCategories = function (categoryId) {
return $http.post(urlBase + "GetAllQuestions", { categoryId: categoryId })
.success(function (data, status, headers, config) {
})
.error(function (data, status, headers, config) {
});
return dataFactory;
});发布于 2015-01-16 10:42:35
我认为代码的问题是,您将id作为url的一部分传递,而不是在ajax请求的数据中传递id。
不要像下面这样在url中传递数据
//do not attach categoryId
urlBase + "GetAllQuestions/" + categoryId而不是在请求的数据参数中传递数据,如下所示
data: { test: 'test' }url将是urlBase + "GetAllQuestions
var req = {
method: 'POST',
url: 'http://example.com',
headers: {
'Content-Type': undefined
},
data: { test: 'test' },
}
$http(req).success(function(){...}).error(function(){...});还有一件事是调用函数来获取数据,而不是使用Get方法而不是Post方法。
https://stackoverflow.com/questions/27982088
复制相似问题