Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

AjaxÀïµÄonreadystatechangeµÄ×÷ÓÃÊÇʲô

·¢ËÍÒ»¸öÇëÇóºó£¬¿Í»§¶ËÎÞ·¨È·¶¨Ê²Ã´Ê±ºò»áÍê³ÉÕâ¸öÇëÇó£¬ËùÒÔÐèÒªÓÃʼþ»úÖÆÀ´²¶»ñÇëÇóµÄ״̬£¬XMLHttpRequest¶ÔÏóÌṩÁËonreadyStateChangeʼþʵÏÖÕâÒ»¹¦ÄÜ¡£ÕâÀàËÆÓڻص÷º¯ÊýµÄ×ö·¨¡£
onreadyStateChangeʼþ¿ÉÖ¸¶¨Ò»¸öʼþ´¦Àíº¯ÊýÀ´´¦ÀíXMLHttpRequest¶ÔÏóµÄÖ´Ðнá¹û£¬È磺
ajaxObj=createAjaxObject();
var url="/MyTodoes/FetchText?id="+id; 
ajaxObj.open("Get",url,true);
ajaxObj.onreadyStateChange=changeTabCallBack;
ajaxObj.send(null);
onreadyStateChangeʼþÊÇÔÚreadyStateÊôÐÔ·¢Éú¸Ä±äʱ´¥·¢µÄ£¬readyStateµÄÖµ±íʾÁ˵±Ç°ÇëÇóµÄ״̬£¬ÔÚʼþ´¦Àí³ÌÐòÖпÉÒÔ¸ù¾ÝÕâ¸öÖµÀ´½øÐв»Í¬µÄ´¦Àí¡£ readyStateÓÐÎåÖÖ¿ÉÈ¡Öµ0£ºÉÐδ³õʼ»¯£¬1£ºÕýÔÚ¼ÓÔØ£¬2£º¼ÓÔØÍê±Ï£¬3£ºÕýÔÚ´¦Àí£»4£º´¦ÀíÍê±Ï¡£Ò»µ©readyStateÊôÐÔµÄÖµ±ä³ÉÁË4£¬¾Í¿ÉÒÔ´Ó·þÎñÆ÷·µ»ØµÄÏìÓ¦Êý¾Ý½øÐзÃÎÊÁË¡£
ͨ³£ÔÚʼþÖÐÅжÏreadyStateµÄÖµÊÇÔÚÇëÇóÍê±Ïʱ²Å×ö´¦Àí£¬È磺
function changeTabCallBack(){
  if(ajaxObj.readyState==4){
     // ÏÂÒ»²½ÑéÖ¤
  }
}
Status´æ´¢ÁË·þÎñÆ÷¶Ë·µ»ØµÄHttpÇëÇóÏìÓ¦´úÂ룬Ëü±íʾÇëÇóµÄ´¦Àí½á¹û£¬³£¼ûÏìÓ¦´úÂëµÄº¬ÒåÈçÓÒ¡£
ÔÚAjax¿ª·¢ÖУ¬×î³£ÓþÍÊÇ200Õâ¸öÏìÓ¦Â룬´úÂëÈçÏ£º
function changeTabCallBack(){
  if(ajaxObj.readyState==4){
    if(ajaxObj.status==200){
       // ·þÎñ¶Ë·µ»ØÁËÕýÈ·Êý¾Ý£¬¿ªÊ¼ÏìÓ¦´¦Àí
    }
  }
}
Http״̬Âë º¬Òå
200 ÇëÇó³É¹¦
202 ÇëÇó±»½ÓÊܵ«´¦ÀíδÍê³É
400 ´íÎóÇëÇó
404 ÇëÇó×ÊԴδÕÒµ½
500 ÄÚ²¿·þÎñÆ÷´íÎó


Ïà¹ØÎĵµ£º

ÓÃGlassfishºÍNetBeans±àдµÚÒ»¸öAJAX³ÌÐò


By Jason.Huang@sun.COM
,

8/1/07
 
B/S½á¹¹µÄÓ¦ÓÃËƺõÒѾ­³ÉΪÁËĬÈϵķ½Ê½,´ó¼ÒÿÌ쿪Æô¹Ø±Õ×î¶àµÄÓ¦ÓÃÎÒÏëÓ¦¸ÃÊÇÄúµÄWebä¯ÀÀÆ÷.B/S½á¹¹µÄÓ¦ÓÃ×î´óµÄÓŵã¾ÍÊÇ·½±ã,¿Í»§¶ËʲôҲ
²»ÐèÒª°²×°¾Í¿ÉÒÔʹÓÃÎÒÃǵÄÓ¦ÓÃ.
µ±È»B/S½á¹¹µÄһЩÌصãÒ²¶Ô»ùÓÚÕâÖÖ·½Ê½Ó¦ÓõĿª·¢ºÍÉè¼Æ²úÉúÁËÓ°Ïì.
×îµäÐ͵ÄÎÊÌâ¾ÍÊÇÿ ......

WCFÖеķþÎñºÍASP.NET AJAXÖеÄWebService

WCFµÄ¼Ü¹¹£ºusing System.ServiceModel;
ÆõÔ¼:Contract
[ServiceContract]
public partial interface IContract
{
        [OperationContract]
        string DocumentWebHostUrl();
}
·þÎñ£ºService
[ServiceBehavior(IncludeException ......

ʹÓÃAjaxµÄһЩԭÔò

1.Ç°¡¢¶Ëºó¶¼Òª×öºÃ°²È«µÄ°Ñ¹Ø¹¤×÷
ÓÉÓÚAjaxÒ²»á½ÓÊÕºó¶Ë´«ËÍÀ´µÄ×ÊÁÏ£¬¶ÔÕâЩ×ÊÁ϶¼Òª²É²»ÐÅÈÎ̬¶È£¬±ØÐë¼ÓÒÔ¼ì²é¡£
2.¾¡Á¿ÒÔHTTP POST·½·¨´«Êä×ÊÁÏ
ËäÈ»POST²¢·ÇÍòÎÞһʧ£¬µ«±ÈÆðGETÖÁÉÙ½ÏΪ°²È«¡£
3.²»ÒªÖ±½ÓÓÃevalº¯Ê½»½ÆðJSONÎï¼þ
JSONÊDzÉÓÃJavaScriptÎï¼þʵ×ÖµÄ×ÊÁϸñʽ£¬´Óºó¶Ë´«µ½Ajax³Ìʽʱ£¬±ØÐë²ÉÓÃevalº ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ