`Angularjs`用`PARAMETERS`调用`WebMethod`

时间:2016-04-02 06:31:18

标签: c# asp.net .net angularjs webmethod

如何使用[WebMethod]将参数发布到angularjs

我的angularjs脚本是::

app.factory('checkAvabService', function ($http) {
    return {
        checkFare: function () {
            return $http.post('onewaydomflt.aspx/checkAvab', { 

             data:{test:"hello"} //post test as parameter to web method

          })
        }
    };
});

我的网络方法是::

[System.Web.Services.WebMethod]
public static string checkAvab(string test)  // string test is not accept value "hello"
{
    string x = test;
    return x;
}

此处我没有测试参数值你好WebMethod

这段代码出了什么问题。

1 个答案:

答案 0 :(得分:2)

只需传递$http.post调用的第二个参数中的数据,该参数以JSON格式获取数据。无需在您传递的对象中再次使用data

return $http.post('onewaydomflt.aspx/checkAvab', {test:"hello"})
相关问题