C# code
[System.Web.Services.WebMethod]
public static string[] GetStringArray(string s, int cnt)
{
string[] stringArray = new string[cnt];
Random rnd = new Random();
for (int i = 0; i < cnt; i++)
{
stringArray[i] = string.Format("Random{0}: {1}-{2}",i, s, rnd.Next(cnt));
}
//throw new Exception("亲爱的错误");
System.Threading.Thread.Sleep(3000);
return stringArray;
}
3、可以把script代码放到.js文件里,如Scripts目录下的MyScript.js内。
JScript code
function CallWebMethod(prefix,count)
{
$get('result').innerText = "请稍侯...";
PageMethods.GetStringArray(prefix, count, OnSuccess, OnFailed);
return false;
}
function OnSuccess(stringArray)
{
var s = "";
for(var i = 0; i < stringArray.length; i++)
{
s += stringArray[i] + "\n";
}