1
매개 변수를 webmethod에 전달하려고하지만 아무런 조치가 없습니다. 메소드와 프로토 타입 아약스 요청에서 매개 변수를 삭제하고 모든 것이 정상이지만 매개 변수를 사용하려고 할 때 작동하지 않습니다. 여기 내 코드 :프로토 타입에서 웹 메서드에 매개 변수를 전달하는 방법
<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);
}
내 실수는 어디에서 볼 수 있습니까?
이것은 위의 예제 코드도 작동하지만 매개 변수는 GET 대신 POST 매개 변수로 전달됩니다. ''method ''를''method ':''method':''post''로 변경하면 같은 결과를 얻을 수 있습니다 –