ajax ¶þ¼¶Áª¶¯
function CreateXmlHttp()
{
if(window.ActiveXObject)
{
try
{
XmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){};
try
{
XmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e){};
}
else if(window.XMLHttpRequest)
{
try{
XmlHttp=new XMLHttpRequest();
}
catch(e){};
}
else
{
window.alert('Çë¼ì²éÄãµÄä¯ÀÀÆ÷!');
}
}
//»ñÈ¡¿Ø¼þµÄ±àºÅ
function $(id)
{
return document.getElementById(id)
};
//¸ù¾ÝÓû§ËùÑ¡µÄÇøµÄÃû³Æ ¼ÓÔظÃÇøËùÓÐѧУÃû³Æ
var getSchoolName=function(obj)
{
var drop1=$("DropSchool");
CreateXmlHttp();
var url="GetSchoolInfo.ashx?id="+escape(obj)+"&num="+new Date().getTime();
XmlHttp.open("GET",url,true);
XmlHttp.onreadystatechange=function()
{
if(XmlHttp.readyState==4 &&XmlHttp.status==200)
{
drop1.options.length=0;
// drop1.options.add(new Option("ÇëÑ¡ÔñËùÔÚѧУ!","ÇëÑ¡ÔñËùÔÚѧУ!"));
if(XmlHttp.responseText=="No")
{
drop1.options.length=0;
drop1.options.add(new Option("¸ÃÇø»¹Ã»ÓÐÏÂÊôѧУ","¸ÃÇø»¹Ã»ÓÐÏÂÊôѧУ"));
return false;
}
var text=XmlHttp.responseText.split(",");
for(var i=0;i<text.length;i++)
{
var name=text[i].split("-");
var NewOption=document.createElement("Option");
NewOption.value=name[0];
NewOption.innerText=name[1];
drop1.appendChild(NewOption);
if(drop1.options.length==1)
{
}
else
{
$("DropSchool").disabled=false;
}
for(var j=0;j<drop1.options.length;j++)
{
if(drop1.options[j].selected)
{
$("HiddenFiled1").value=drop1.options[i].text;
}
}
}
}
}
XmlHttp.send(null);
}
ashx´úÂë
int id = Convert.ToInt32(context.Request.QueryString["id"].ToString());
StringBuilder sb
Ïà¹ØÎĵµ£º
×î½üÍøÉÏÌáµÄºÜ¶àµÄÒ»¸öиÅÄî¾ÍÊÇ AJAX ÁË, ÄÇô, AJAX ÊÇʲôÄØ? ÒÔÏÂÄÚÈÝÒýÓÃÍøÉÏ×ÊÁÏ:
AJAXÈ«³ÆΪ“Asynchronous JavaScript and XML”£¨Òì²½JavaScriptºÍXML£©£¬ÊÇÖ¸Ò»ÖÖ´´½¨½»»¥Ê½ÍøÒ³Ó¦ÓõÄÍøÒ³¿ª·¢¼¼Êõ¡£ËüÓлúµØ°üº¬ÁËÒÔϼ¸ÖÖ¼¼Êõ£º
Ajax£¨Asynchronous JavaScript + XML£©µÄ¶¨Òå
»ùÓÚ web±ê×¼£¨sta ......
ÆÊÎö AJAX »Ø·¢
ÈôҪʹ ASP.NET Ò³Ãæ³ÉΪ²¿·Ö³ÊÏÖµÄÒ³Ã棬Ê×ÏȱØÐëÏòÒ³ÃæÌí¼ÓÒ»¸ö½Å±¾¹ÜÀíÆ÷£¬È»ºóͨ¹ýʹÓà UpdatePanel ¿Ø¼þ½øÐзâ×°£¬´Ó¶ø¶¨Òå¿É¶ÀÁ¢¸üеÄÇøÓò¡£ÀýÈ磺
< ?xml:namespace prefix = asp />
< asp:ScriptManager runat="server">< /asp:ScriptManager>
< asp:UpdatePanel id=Upda ......
Web¿ª·¢Õß²»»á×¢Òâµ½ÓÉ “AJAX(Asynchronous JavaScript And XML)”Ëù´øÀ´µÄ¼¤Çé¡£²»·ÑÁ¦Æø¾ÍÄÜ´´½¨ÏñGoogle SuggestÄÇÑùµÄÖÇÄÜÍøÕ¾»òÕßÏñGmailÄÇÑù»ùÓÚWebµÄÓ¦ÓóÌÐò£¬ÕâÔںܴó³Ì¶ÈÉÏÒª¹é¹¦ÓÚÕâÖÖ¼¼Êõ¡£È»¶ø£¬°éËæ×ÅAJAXÓ¦ÓóÌÐòµÄ·¢Õ¹£¬ÎÒÃÇ·¢ÏÖÁËËüµÄһЩ²»×ãÖ®´¦£¬ÎÒÃÇ·¢ÏÖËüµÄ°²È«Â©¶´Ò²ÔÚÖð½¥±ä´ó£¬¾ÍÏñÂý ......
1¡¢µ±¸Ä±ä·þÎñÆ÷ÉϵÄ״̬ʱӦµ±Ê¹ÓÃPOST·½·¨¡£²»Í¬ÓÚGET£¬ÐèÒªÉèÖÃXML- HttpRequest¶ÔÏóµÄContent-TypeÊײ¿£¬ÈçÏÂËùʾ£º
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ÓëGET²»Í¬£¬POST²»»áÏÞÖÆ·¢Ë͸ø·þÎñÆ÷µÄ¾»ºÉµÄ´óС£¬¶øÇÒPOSTÇëÇó²»Äܱ£Ö¤ÊÇÃݵȵġ£
Äã×öµÄ´ó¶àÊýÇëÇó¿ÉÄܶ¼ÊÇG ......
//AjaxÓ¦ÓõÄÎå¸ö²½Öè
//1.´´½¨XMLHttpRequest¶ÔÏó
var xmlHttp=createXMLHttpRequest();
function createXMLHttpRequest()
{
var xmlHttp;
if(Window.XMLHttpRequest)
{
//IE6ÒÔÉÏ°æ±¾ºÍÆäËûä¯ÀÀÆ÷ÄÚÖÃXMLHttpRequest¶ÔÏó
xmlHttp=new XMLHttpRequest();
......