using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace DownloadProxy { public partial class RenameDownload : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } [System.Web.Services.WebMethod] //[System.Web.Script.Services.ScriptMethod()]
//[System.Web.Services.WebMethod(MessageName="getRangRandom")]
//[System.Web.Script.Services.ScriptMethod(UseHttpGet=true)] public static string AjaxTest(string name) { return "Hello," + name + "!" ; } } }
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RenameDownload.aspx.cs" Inherits="DownloadProxy.RenameDownload" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <asp:scriptmanager runat="server" EnablePageMethods="true"></asp:scriptmanager> <script type="text/javascript"> PageMethods.set_timeout(5000); PageMethods.set_defaultFailedCallback = "OnFailed"; PageMethods.AjaxTest("knife", OnSucceed); function OnSucceed(Message) { alert(Message); } function OnFailed(ErrorHander) { var ErrorMessage = 'Timeout:' + ErrorHander.get_timedOut() + ',Error Message:' + ErrorHander.get_message(); ErrorMessage = ErrorMessage + ',Exception Type:' + ErrorHander.get_exceptionType() + ',Error Loaction:' + ErrorHander.get_stackTrace(); alert(ErrorMessage); } </script> </form> </body> </html>