ajax XMLHttpRequest.readyStateÖÐStateµÄ"S"Òª´óд
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>xmlhttprequest ajax demo</title>
<mce:script type ="text/javascript" language ="javascript" ><!--
var req; //¶¨Òå±äÁ¿£¬ÓÃÀ´´´½¨xmlhttprequest¶ÔÏó
function creatReq() // ´´½¨xmlhttprequest,ajax¿ªÊ¼
{
var url="events_msg"; //ÒªÇëÇóµÄ·þÎñ¶ËµØÖ·
if(window.XMLHttpRequest) //·ÇIEä¯ÀÀÆ÷¼°IE7(7.0¼°ÒÔÉÏ°æ±¾)£¬ÓÃxmlhttprequest¶ÔÏó´´½¨
{
req=new XMLHttpRequest();
}
else if(window.ActiveXObject) //IE(6.0¼°ÒÔÏ°汾)ä¯ÀÀÆ÷ÓÃactivexobject¶ÔÏó´´½¨,Èç¹ûÓû§ä¯ÀÀÆ÷½ûÓÃÁËActiveX,¿ÉÄÜ»áʧ°Ü.
{
req=new ActiveXObject("Microsoft.XMLHttp");
}
if(req) //³É¹¦´´½¨xmlhttprequest
{
req.open("GET",url,true); //Óë·þÎñ¶Ë½¨Á¢Á¬½Ó(ÇëÇó·½Ê½post»òget£¬µØÖ·,true±íʾÒì²½)
req.onreadystatechange = callback; //Ö¸¶¨»Øµ÷º¯Êý
req.send(null); //·¢ËÍÇëÇó
}
}
function callback() //»Øµ÷º¯Êý£¬¶Ô·þÎñ¶ËµÄÏìÓ¦´¦Àí£¬¼àÊÓresponse״̬
{
alert(req.readyState)
if(req.readyState==4) //ÇëÇó״̬Ϊ4±íʾ³É¹¦
{
if(req.status==200) //http״̬200±íʾOK
{
Dispaly(); //ËùÓÐ״̬³É¹¦£¬Ö´Ðд˺¯Êý£¬ÏÔʾÊý¾Ý
}
else //http·µ»Ø״̬ʧ°Ü
{
alert("·þÎñ¶Ë·µ»Ø״̬" + req.statusText);
}
}
else //ÇëÇó״̬»¹Ã»Óгɹ¦£¬Ò³ÃæµÈ´ý
{
document.getElementById("myTime").innerHTML="Êý¾Ý¼ÓÔØÖÐ";
}
}
function Dispaly() //½ÓÊÜ·þÎñ¶Ë·µ»ØµÄÊý¾Ý£¬¶ÔÆä½øÐÐÏÔʾ
{
document .getElementById ("myTime").innerHTML =req.responseText;
}
// --></mce:script&
Ïà¹ØÎĵµ£º
Ajax µÄ¸ÅÄ
AjaxÌá³öÕßJesse James GarrettÔÚ¡¶Ajax:Ò»¸öWebÓ¦ÓõÄÐÂ;¾¶¡·ÖÐÌáµ½AjaxΪ“Asynchronous JavaScript + XML”µÄ¼ò³Æ£¬Ò²¾ÍÊÇÒì²½µÄJavaScriptºÍXML´¦Àí¡£
ÆäÖаüº¬£º
ÓÃXHTMLºÍCSS½øÐлùÓÚ±ê×¼µÄ±íʾ·½Ê½£º
¡¡¡¡²ÉÓÃDOM(document object model)¶¯Ì ......
AJAX¼¼ÊõÓ¦ÓÃÏê½â ÊÕ²Ø
AJAXÊÇAsynchronous JavaScript and XML µÄËõд¡£Ëü²¢²»ÊÇÒ»ÃÅеÄÓïÑÔ»ò¼¼Êõ£¬Ëüʵ¼ÊÉÏÊǼ¸Ïî¼¼Êõ°´Ò»¶¨µÄ·½Ê½×éºÏÔÚÒ»ÔÚͬ¹²µÄÐ×÷Öз¢»Ó¸÷×ÔµÄ×÷Óã¬Ëü°üÀ¨:ʹÓÃXHTMLºÍCSS±ê×¼»¯³ÊÏÖ;ʹÓÃDOMʵÏÖ¶¯Ì¬ÏÔʾºÍ½»»¥;ʹÓÃXMLºÍXSLT½øÐÐÊý¾Ý½»»»Óë´¦Àí;ʹÓÃXMLHttpRequest½øÐÐÒì²½Êý¾Ý¶ÁÈ¡;×î ......
°Ñ×Ô¼ºÐ´µÄjqueryдÏÂÀ´
±ÈÈçÏÖÔÚÓÐÒ»¸ö½çÃ棬·Ö×óÓÒÁ½²à£¬µ±µã»÷×ó²àµÄ±êÇ©£¬È»ºóÔÚÓÒ²à¿òÏÔʾ£¬ÊµÏÖÎÞˢм¼Êõ£¬ÕâÊÇ×î¼òµ¥µÄajaxÓ¦Óá¡
function touser() {
$.ajax({
url: "UserTable.aspx?timeStamp=" + new Date().getTime(),
success: function(msg) {
$("#ma ......