我想将参数传递给 webmethod 但没有操作。我从方法和原型 ajax 请求中删除参数,一切正常,但是当我想使用参数时它不起作用。这是我的代码:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js"></script>
<script>
var xRequest = new Ajax.Request('PrototypeTest.aspx/Test', {
method: 'post',
parameters: { "id": 'asdf' },
contentType: 'application/json; charset=utf-8',
onSuccess: function (val) {
var brands = val.responseText.evalJSON().d.evalJSON();
brands.each(function (brand) {
alert(brand.Name);
});
},
onerror: function (val) {
debugger;
alert('hata');
}
});
</script>
[WebMethod]
public static string Test(string id)
{
List<brand> brands = new List<brand>();
brands.Add(new brand()
{
Name = "BMW",
IsActive = true
});
var json = new JavaScriptSerializer();
return json.Serialize(brands);
}
我的错误在哪里?