使用Ajax如何從在的WebMethod angular2
$.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);
}
});
獲得的數據在Javascript中嘗試以下的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',直到那時它不會工作.. –
@ Pankaj Parkar你能給我代碼什麼需要改變我的代碼 – Pravin
.net項目和angular2在同一個應用服務器上 – Eswar