我正在使用 http post 使用以下代码从网络服务获取数据..
$http({
method: "post",
url: "SurveyQuestions.asmx/GetSurveyQuestions",
data: JSON.stringify({"empl_id" : '12345' , "Year" : '2015' }),
headers: { 'Content-Type': 'application/json' },
dataType: "json",
contentType: "application/json; charset=utf-8",
}).success(function (response) { //do something})
上面的代码使用不带参数的“get”可以正常工作。
我的帖子网络服务是
<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=False)> _
Public Sub GetSurveyQuestions(ByVal Empl_id as string, ByVal Year as string)
Try
//get list of records
Dim js As JavaScriptSerializer = New JavaScriptSerializer
Context.Response.Write(js.Serialize(listSurveyQuestions))
Catch ex As Exception
End Try
End Sub
Web 服务执行正常并将数据返回到方法,但 $http
中的响应为空并出错。
最佳答案
你只是尝试传递仅在 url 最后添加的对象。
这是我的情况,我只是添加员工 ID。如果您仅发送员工对象,它也会正确。
$scope.removeEmployee = function(employee) {
var method = 'DELETE';
var url = 'http://localhost:8080/AngularJSWithRestful/rest/product/Delete/' + employee.id ;
$http({
method : method,
url : url,
}).then(function successCallback(response) {
$scope.product = response.data.product;
}, function errorCallback(response) {
});
};
关于javascript - Angular js $http post 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38388093/