在 Javascript 中使用 Ajax
$.ajax({
type: "Get",
url: "AttendanceMaster.aspx/GetDistinctBatch",
data: "{}",
contentType: "application/json; charset=utf-8",
datatype: "jsondata",
async: "true",
success: function(response) {
},
error: function(response) {
alert("(allstudent )" + response.status + ' Error ' + response.statusText);
}
});
尝试跟随 angular2
return this._http.get("AttendanceMast.apsx/GetDistinctBatch")
.map((response) => response.toString());
返回
{ "_isScalar": false, "source": { "_isScalar": false }, "operator": {} }
C#
[System.Web.Services.WebMethod]
public static string GetDistinctBatch()
{
return "welcome Angular 2";
}
1)在angular2中如何使用?
查看下面的错误
最佳答案
您的方法只是返回 Observable
,它们将只是一个函数。 Observable
本质上是惰性的。在您订阅它们之前,它们不会被执行。
AttendanceMast() {
return this._http.get("AttendanceMast.apsx/GetDistinctBatch")
.map((response) => response.toString()); //better do it response.json();
}
myService.AttendanceMast().subscribe(
data => console.log(data);
)
关于http - 如何从angular2中的WebMethod获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41436483/