ajax¾Ö²¿Ìá½»
ʵÏÖ¹¦ÄÜ£ºµ¥»÷°´Å¥£¬½«´ÓÊý¾Ý¿â»ñÈ¡µÄÊý¾Ý·µ»Ø¸øÎı¾¿ò1(Ë¢ÐÂÎı¾¿ò1)£¬¶øÎı¾¿ò2²»Ë¢ÐÂ
Ò³Ãæ1£ºtest.html
<!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>
<title>ASP.NETÏÂAjax¾Ö²¿Ë¢Ð¼òµ¥Ó¦ÓÃ</title>
<mce:script language=javascript><!--
function getData()
{
/* Create a new XMLHttpRequest object to talk to the Web server */
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("ÄúµÄä¯ÀÀÆ÷²»Ö§³ÖAJAX£¡");
return false;
}
}
}
xmlHttp;.open("get","test.aspx",false);
xmlHttp;.send();
if(xmlHttp;.readyState == 4 && xmlHttp;.status == 200)
{
document.getElementById("tb1").innerText= xmlHttp;.responseText;
}
}
// --></mce:script>
</head>
<body>
<input id="tb1" type="text"/><button onclick="getData()">µã»÷</button>
<br/>
<input id="tb2" type="text" />
</body>
</html>
Ò³Ãæ2Ö÷Òª´úÂ룺test.aspx
protected void Page_Load(object sender, EventArgs e)
{
//Êý¾Ý¿â²Ù×÷´úÂë
......
//°Ñ´ÓÊý¾Ý¿âÈ¡³öµÄÊý¾ÝÓÃResponse.Write·µ»Ø
Response.Write("ÎÒÊǺǫ́»ñÈ¡µÄÊý¾Ý");
}
Ïà¹ØÎĵµ£º
ÔÚ ASP .NET µÄ AJAX ¿Ø¼þÖÐ TabContainer µÄ CSS ÑùʽµÄ±àд¾ßÓÐÒ»¶¨µÄ¸ñʽ¹æ·¶¼°ÃüÃû¹æÔò£¬ÈçÏÂͼ£º
¾ßÌåµÄ CSS ÑùʽµÄ±àдΪ£º
.ajax_tab_menu .ajax__tab_header /*ÕûÌå°´Å¥µ×Ñùʽ*/
{
font-family:ËÎÌå;
height:29px;
font-size:12px;
background:#181c1f repeat-x bottom;
}
.ajax_tab_menu .ajax__tab ......
Ò»¸öajaxÇëÇóÒ»¸öjspÎļþ£¬²Ù×÷³É¹¦,jspÎļþout.println("1");µ«ÊÇÿ´Î³É¹¦ºóxmlHttp.responseText=='1'×ÜÊÇΪfalse£¬
ÓÃencodeURIComponent¿´xmlHttp.responseText£¬·¢ÏÖ×îºó¶àÁË%0A%0D£¬°Ù¶ÈһϠÓÃÀ´ÊÇ»»ÐУ¬
jspÎļþÖеÄout.println……°ÑlnÈ¥µôÔÙ´Î±È½Ï ³É¹¦ = =¡ ......
AjaxÖ±½Ó¿çÓò·ÃÎÊ£¬»á³öÏÖûÓÐȨÏ޵ĴíÎó£¬Ò»¸ö±È½Ï¼òµ¥¿ÉÐеĽâ¾ö·½°¸ÈçÏ£º
×öÒ»¸ö ajaxÇëÇóµÄ ´úÀíservlet »òÕßjsp£¬
ajaxÇëÇóservlet»òjsp´úÀí£¬ÓÉservlet»òjsp´úÀíÈ¥ÇëÇóajaxÒª·ÃÎʵÄaction£¬È»ºóÔÙ½«actionµÄÏìÓ¦ÐÅÏ¢·µ»Ø¸øajax¼´¿É£¬
servlet»òjsp³äµ±ÖнéÈ˵ĽÇÉ«
servlet »ò jsp ´úÀíµÄ ºËÐÄ´úÂëÈçÏ£ ......
function verify() {
//½â¾öÖÐÎÄÂÒÂéÎÊÌâµÄ·½·¨1£¬Ò³Ãæ¶Ë·¢³öµÄÊý¾Ý×÷Ò»´ÎencodeURI£¬·þÎñÆ÷¶ÎʹÓÃnew String(old.getBytes("iso8859-1"),"UTF-8");
//½â¾öÖÐÎÄÂÒÂéÎÊÌâµÄ·½·¨2£¬Ò³Ãæ¶Ë·¢³öµÄÊý¾Ý×÷Á½´ÎencodeURI£¬·þÎñÆ÷¶ÎʹÓÃURLDecoder.decode(old,"UTF-8")
var url = &qu ......