I've encountered an issue while trying to pass a parameter to a web method. Despite removing the parameters from both the method and prototype ajax request, everything works fine. However, when I attempt to use a parameter, it fails to work. Here is my code snippet:
<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);
}
Can anyone spot where I might be going wrong?