如何通过 Angular $http 将字符串发送到 C# ASP.NET 后端?
How to send string over Angular $http to C# ASP.NET backend?
我想通过 Angular $http 将字符串发送到我的 ASP.NET C# 后端。我正在使用网络表单。但是,我收到以下错误:
POST http://localhost:49730/Default.aspx/get_requested_table 404 (Not Found)
我的 Angular 控制器如下所示:
App.controller("MainCtrl", function ($scope, $http) {
$scope.request_table = function (tableName) {
$http
.post("Default.aspx/get_requested_table", tableName)
.success(function (data) {
console.log("Success, it worked!");
});
};
});
我的 HTML 看起来像这样:
<button ng-click="request_table('tblMain')" type='button'>GET IT</button>
还有我的 ASP.NET C# 文件(又名 Default.aspx.cs):
public static string myTable;
[WebMethod]
public static string get_requested_table(string tableName)
{
var myTable = tableName;
Console.Write(myTable);
return myTable;
}
我是不是做错了什么导致出现这个错误?我如何使用 Angular 的 $http 方法与我的 C# 后端通信?
您没有发送 key/value 对
尝试
$http.post("Default.aspx/get_requested_table", {tableName: tableName})
我想通过 Angular $http 将字符串发送到我的 ASP.NET C# 后端。我正在使用网络表单。但是,我收到以下错误:
POST http://localhost:49730/Default.aspx/get_requested_table 404 (Not Found)
我的 Angular 控制器如下所示:
App.controller("MainCtrl", function ($scope, $http) {
$scope.request_table = function (tableName) {
$http
.post("Default.aspx/get_requested_table", tableName)
.success(function (data) {
console.log("Success, it worked!");
});
};
});
我的 HTML 看起来像这样:
<button ng-click="request_table('tblMain')" type='button'>GET IT</button>
还有我的 ASP.NET C# 文件(又名 Default.aspx.cs):
public static string myTable;
[WebMethod]
public static string get_requested_table(string tableName)
{
var myTable = tableName;
Console.Write(myTable);
return myTable;
}
我是不是做错了什么导致出现这个错误?我如何使用 Angular 的 $http 方法与我的 C# 后端通信?
您没有发送 key/value 对
尝试
$http.post("Default.aspx/get_requested_table", {tableName: tableName})