Вот ваш «полностью упрощенный пример кода»:
Ваш WebMethod (поместите его в коде example.aspx позади файла):
[WebMethod(CacheDuration = 0, EnableSession = true)]
public static YourResultType YourMethodName(string param1,int param2)
{
YourResultType result=new YourResultType();
result.x1=true;
result.x2="The Response can be in any type";
return result;
}
Ваш тип результата:
public class YourResultType
{
public YourResultType(){}
public bool x1;
public string x2;
}
Коды JavaScript (на основе jQuery):
$.ajax({
type: "POST", cache: false,
url: "example.aspx/YourMethodName",
data: "{'randomparam':'" + ((new Date()).getTime()) +
//randomparam is for preventing cache
"','param1':'param1Value','param2':'param2Value'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
if (msg.hasOwnProperty("d")) msg = msg.d;
//And Here, The msg parameter,
//contains the result of the WebMethod
//and you can use that like this:
alert(msg.x1);
alert(msg.x2);
}
});