C# `Angularjs`使用`PARAMETERS`调用`WebMethod``
如何使用C# `Angularjs`使用`PARAMETERS`调用`WebMethod``,c#,asp.net,.net,angularjs,webmethod,C#,Asp.net,.net,Angularjs,Webmethod,如何使用angularjs将参数发布到[WebMethod] 我的angularjs脚本是: app.factory('checkAvabService', function ($http) { return { checkFare: function () { return $http.post('onewaydomflt.aspx/checkAvab', { data:{test:"hello"} //post t
angularjs
将参数发布到[WebMethod]
我的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
})
}
};
});
我的Web方法是::
[System.Web.Services.WebMethod]
public static string checkAvab(string test) // string test is not accept value "hello"
{
string x = test;
return x;
}
这里我没有得到测试参数值hello toWebMethod
这段代码有什么问题。只需在
$http.post
调用的第二个参数中传递数据,该调用以JSON格式获取数据。在您传递的对象中不需要再次使用数据
return $http.post('onewaydomflt.aspx/checkAvab', {test:"hello"})
非常感谢你。。潘卡杰·帕克。现在webmethod接受参数fine。。。谢谢again@JBNizet谢谢你的提醒。。但我想知道,在向ASP.NETMVC-4操作发布任何数据时,为什么我们需要以字符串化格式传递请求正文。我只是好奇一下。我对ASP.NETMVC-4一无所知,也不知道你所说的“字符串化格式”是什么意思。@JBNizet我的意思是,在将数据发送到服务器之前,我会对它进行字符串化(
JSON.strigify(data)
)。我不明白这有什么用处。Angular将传递到$http的对象默认转换为JSON:如果请求配置对象的数据属性包含对象,则将其序列化为JSON格式。