ajax °²È«ÐÔ
ÍêÈ«ÊÊÓÃASP.NETµÄÈÏÖ¤»úÖÆ
–¿ÉÒÔʹÓÃFormsAuthentication
•WebService·½·¨¿ÉÒÔ²Ù×÷Cookie
–Impersonation
–PrincipalPermission
WebService7.cs Code
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
/// <summary>
/// WebService7 µÄժҪ˵Ã÷
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class WebService7 : System.Web.Services.WebService {
public WebService7 () {
//Èç¹ûʹÓÃÉè¼ÆµÄ×é¼þ£¬ÇëÈ¡Ïû×¢ÊÍÒÔÏÂÐÐ
//InitializeComponent();
}
[WebMethod]
public string HelloWorld() {
if (!HttpContext.Current.User.Identity.IsAuthenticated)
{
throw new ApplicationException("please Login In");
}
return "Hello "+HttpContext.Current.User.Identity.Name;
}
}
Default8.aspx Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default8.aspx.cs" Inherits="Default8" %>
<!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 ID="aaa" ScriptMode=Debug>
<Services>
<asp:ServiceReference Path="WebService7.asmx" />
</Services>
</asp:ScriptManager>
<mce:script language=javascript type="text/javascript"><!--
function GetMessage()
{
WebService7.HelloWorld(getresult);
}
function getresult(result)
{
alert(result);
}
// --></mce:script>
<input id="Button1" type="button" value="button" on
Ïà¹ØÎĵµ£º
AjaxÖÐsend·½·¨²ÎÊýµÄʹÓÃ
Ò»°ãÇé¿öÏ£¬Ê¹ÓÃAjaxÌá½»µÄ²ÎÊý¶àÊÇЩ¼òµ¥µÄ×Ö·û´®£¬¿ÉÒÔÖ±½ÓʹÓÃGET·½·¨½«ÒªÌá½»µÄ²ÎÊýдµ½open·½·¨µÄurl²ÎÊýÖУ¬´Ëʱsend·½·¨µÄ²ÎÊýΪnull¡£
ÀýÈç £º
var url = "login.jsp?user=XXX&pwd=XXX";
xmlHttpRequest.open("GET",url, ......
ÇëÇó·½Ê½£¬·ÖΪGETÓëPOST£º
GET
×îΪ³£¼ûµÄHTTPÇëÇó£¬ÆÕͨÉÏÍøä¯ÀÀÒ³Ãæ¾ÍÊÇGET¡£GET·½Ê½µÄ²ÎÊýÇëÇóÖ±½Ó¸úÔÚURLºó£¬ÒÔÎʺſªÊ¼¡££¨JSÖÐÓÃwindow.location.search»ñµÃ£©¡£²ÎÊý¿ÉÒÔÓÃencodeURIComponent½øÐбàÂ룬ʹÓ÷½Ê½:
var EnParam = encodeURIComponent(param);
URLÖ»Ö§³Ö´óÔ¼2KµÄ³¤¶È£¬¼´2 ......
ʲôÊÇ AJAX?
¡¡¡¡AJAX (Òì²½ JavaScript ºÍ XML) ÊǸöвúÉúµÄÊõÓï,רΪÃèÊöJavaScriptµÄÁ½ÏîÇ¿´óÐÔÄÜ.ÕâÁ½ÏîÐÔÄÜÔÚ¶àÄêÀ´Ò»Ö±±»ÍøÂ翪·¢ÕßËùºöÂÔ,Ö±µ½×î½üGmail, Google suggestºÍgoogle MapsµÄºá¿Õ³öÊÀ²ÅʹÈËÃÇ¿ªÊ¼Òâʶµ½ÆäÖØÒªÐÔ.
¡¡¡¡ÕâÁ½Ïî±»ºöÊÓµÄÐÔÄÜÊÇ:
¡¡¡¡ÎÞÐèÖØÐÂ×°ÔØÕû¸öÒ³Ãæ±ãÄÜÏò·þÎñÆ÷·¢ËÍÇëÇó.
¡¡¡ ......
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
/// <summary>
/// Summary description for Commen ......
jQueryÊÇÒ»¸ö¿ÉÒÔ¼ò»¯ JavaScript?ÒÔ¼°AJAX£¨Asynchronous JavaScript
+XML£¬Òì²½JavascriptºÍXML£©±à³ÌµÄJavascript¿â¡£²»Í¬ÓÚÆäËûµÄJavascript¿â£¬jQueryÓÐËû×Ô¼ºµÄÕÜѧ£¬Ê¹Äã¿É
ÒԺܼòµ¥µÄ±àд´úÂë¡£ÕâƪÎÄÕ¾ͻá´øÁìÄã¼ûʶһÏÂjQueryµÄÕÜѧ£¬Ì½ÌÖÒ»ÏÂËûµÄÌØÐÔÒÔ¼°¹¦ÄÜ£¬²¢ÇÒ»á×öһЩajaxµÄʾÀý£¬ÒÔ¼°ÈçºÎʹÓÃplug-
......