更新:2007 年 11 月
在 Web 服务方法请求成功完成后,调用此函数以处理返回数据。
说明: |
|---|
成功回调函数可以具有任何名称。 |
function SucceededCallback(result, userContext, methodName)
{
// Code here to process results from the Web service call.
}
参数
参数 |
定义 |
|---|---|
result |
从 Web 服务方法调用返回的数据。这是一个 JavaScript 对象,其类型对应于 Web 方法返回的 .NET Framework 类型。 |
userContext |
在调用 Web 服务方法时传递的上下文信息。如果未传递上下文信息,则使用 defaultUserContext 对象(如果已定义);否则向回调函数传递 null。userContext 值提供在处理返回数据时可以使用的其他信息。 |
methodName |
调用的 Web 服务方法。methodName 参数提供在处理返回数据时要使用的附加信息。 |
备注
成功回调函数为 JavaScript 函数,可以用于在 Web 服务请求成功完成后处理返回的数据。
可以使用 defaultSucceededCallback 属性将回调函数分配给生成的代理类或其实例。或者,可以在调用 Web 服务方法时传递回调函数。这会重写默认值。
示例
下面的示例演示如何定义成功回调函数。
// Callback function invoked when a call to
// the Web service methods succeeds.
function SucceededCallback(result, userContext, methodName)
{
var message;
switch(methodName)
{
case ("GetDefaultColor"):
case ("SetColor"):
{
// Get the server default color.
message = result.message;
defaultRgb = result.rgb;
// Transform the rgb array into a string.
var serverColor = defaultRgb[0]+ defaultRgb[1] + defaultRgb[2];
// Display the result.
displayResult.style.color = "yellow";
displayResult.style.fontWeight = "bold";
displayResult.style.backgroundColor = "#" + serverColor;
DisplayMessage(message);
break;
}
default:
{
DisplayMessage("Method unknown");
}
}
}
请参见
概念
参考
生成的代理类 defaultFailedCallback 属性
其他资源
Generated Proxy Classes defaultSucceededCallback Property
说明: