Ajax ´íÎó´¦Àí
´íÎó´¦Àí
•µ÷ÓÃʱ¿ÉÒÔÌṩһ¸ö¶îÍâµÄ´íÎ󻨵÷º¯Êý
•°üÀ¨³¬Ê±ºÍ·þÎñÆ÷¶ËÅ׳öµÄÒì³£
•³¬Ê±Ö»ÄÜÉèÖÃÔÚWebService¼¶±ð
–»òÕßÉèÖÃÔÚPageMethods¶ÔÏóÉÏ
–ÎÞ·¨ÔÚÿ¸öMethodCallʱָ¶¨
•Sys.Net.WebServiceError
–timedout¡¢message¡¢exceptionType¡¢stackTraceÊôÐÔ
ErrorHandling.asmx Code:
<%@ WebService Language="C#" Class="ErrorHandling" %>
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
using System.Threading;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class ErrorHandling : System.Web.Services.WebService
{
[WebMethod]
public int GetDivision(int a, int b)
{
return a / b;
}
[WebMethod]
public int Timeout()
{
Thread.Sleep(5000);
return 0;
}
}
3_ErrorHandling.aspx Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="3_ErrorHandling.aspx.cs" Inherits="_3_ErrorHandling" %>
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="ErrorHandling.asmx" />
</Services>
</asp:ScriptManager>
<input type="button" value="getDivision" onclick="getDivision(5, 0)" />
<input type="button" value="timeout" onclick="timeout()" />
<mce:script language="javascript" type="text/javascript"><!--
function getDivision(a, b)
{
ErrorHandling.GetDivision(a, b, null, failedCallback);
}
function timeout()
{
ErrorHandling.set_timeout(2000);
ErrorHandling.Timeout(null
Ïà¹ØÎĵµ£º
load(url[,data][,callback])------------->ͨ³£ÓÃÀ´´ÓWEB·þÎñÆ÷ÉÏ»ñÈ¡¾²Ì¬µÄÊý¾ÝÎļþ
url: stringÀàÐÍ ÇëÇóHTMLÒ³ÃæµÄURLµØÖ·
data(¿ÉÑ¡): object ·¢ËÍÖÁ·þÎñÆ÷µÄkey/valueÊý¾Ý
callback(¿ÉÑ¡):function ÇëÇóÍê³Éʱ»Øµ÷º¯Êý
Àý×Ó£º
Ö÷Ò³Ãæ´úÂ룺
<style type="text/css">
* { margin:0; padding ......
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<titl ......
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!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=" ......
ʵʱÊý¾ÝÑéÖ¤ÊÇAJAX¼¼ÊõµÄÒ»´óÓÅÊÆÖ®Ò»¡£Í¨¹ýÓ¦Óô˼¼Êõ£¬strutsÑéÖ¤¿ò¼Ü½«ÔöÇ¿struts MVC£¬²¢Ê¹WebÓ¦ÓóÌÐò¸ü½Ó½üÓÚ×ÀÃæÓ¦ÓóÌÐò¡£
´ËÑéÖ¤¿ò¼ÜÓÃÓÚÑéÖ¤×ֶΡ£ÓÐÐí¶àÔÚWebÓ¦ÓóÌÐòÉϽøÐÐÑéÖ¤µÄ·½·¨¡£ÕâЩ·½·¨¿É·ÖΪÁ½Àࣺ·þÎñÆ÷¶Ë·½·¨ºÍ¿Í»§¶Ë·½·¨¡£StrutsÑéÖ¤¿ò¼ÜÊÇÃæÏò»ùÓÚJavaµÄWebÓ¦Óû·¾³µÄ×î¼Ñ¿ò¼ÜÖ®Ò»¡£ËüÄܹ»ÅäÖÃÓ ......