AJAX£¨XMLHttpRequest£©¿çÓòÇëÇó±Ê¼Ç£¨Ò»£©
ÒÔÏ´úÂëÇëÔÚFirefox 3.5¡¢Chrome 3.0¡¢Safari 4Ö®ºóµÄ°æ±¾ÖнøÐвâÊÔ¡£IE8µÄʵÏÖ·½·¨ÓëÆäËûä¯ÀÀ²»Í¬¡£
¿çÓòÇëÇ󣬹ËÃû˼Ò壬¾ÍÊÇÒ»¸öÕ¾µãÖеÄ×ÊÔ´È¥·ÃÎÊÁíÍâÒ»¸ö²»Í¬ÓòÃûÕ¾µãÉϵÄ×ÊÔ´¡£ÕâÖÖÇé¿öºÜ³£¼û£¬±ÈÈç˵ͨ¹ý style. ±êÇ©¼ÓÔØÍⲿÑùʽ±íÎļþ¡¢Í¨¹ý img ±êÇ©¼ÓÔØÍⲿͼƬ¡¢Í¨¹ý script. ±êÇ©¼ÓÔØÍⲿ½Å±¾Îļþ¡¢Í¨¹ý Webfont ¼ÓÔØ×ÖÌåÎļþµÈµÈ¡£Ä¬ÈÏÇé¿öÏ£¬½Å±¾·ÃÎÊÎĵµÊôÐÔµÈÊý¾Ý²ÉÓõÄÊÇͬԴ²ßÂÔ£¨Same origin policy£©¡£
ÄÇô£¬Ê²Ã´ÊÇͬԴ²ßÂÔÄØ£¿Èç¹ûÁ½¸öÒ³ÃæµÄÐÒé¡¢ÓòÃûºÍ¶Ë¿ÚÊÇÍêÈ«ÏàͬµÄ£¬ÄÇôËüÃǾÍÊÇͬԴµÄ¡£Í¬Ô´²ßÂÔÊÇΪÁË·ÀÖ¹´ÓÒ»¸öµØÖ·¼ÓÔصÄÎĵµ»ò½Å±¾·ÃÎÊ»òÕßÉèÖôÓÁíÍâÒ»¸öµØÖ·¼ÓÔصÄÎĵµµÄÊôÐÔ¡£Èç¹ûÁ½¸öÒ³ÃæµÄÖ÷ÓòÃûÏàͬ£¬Ôò»¹¿ÉÒÔͨ¹ýÉèÖà document.domain ÊôÐÔ½«ËüÃÇÈÏΪÊÇͬԴµÄ¡£
Ëæ×Å Web2.0 ºÍ SNS µÄÐËÆð£¬Web Ó¦ÓöԿçÓò·ÃÎʵÄÐèÇóÒ²Ô½À´Ô½¶à£¬µ«ÊÇ£¬Ôڽű¾ÖнøÐпçÓòÇëÇóÊÇÊÜ°²È«ÐÔÏÞÖƵģ¬Web ¿ª·¢ÈËÔ±ÆÈÇÐÐèÒªÌṩһÖÖ¸ü°²È«¡¢·½±ãµÄ¿çÓòÇëÇó·½Ê½À´Èںϣ¨Mashup£©×Ô¼ºµÄ Web Ó¦Óá£ÕâÑù×öµÄÒ»¸öºÃ´¦¾ÍÊÇ¿ÉÒÔ½«ÇëÇó·Ö̯µ½²»Í¬µÄ·þÎñÆ÷£¬¼õÇáµ¥¸ö·þÎñÆ÷ѹÁ¦ÒÔÌá¸ßÏìÓ¦Ëٶȣ»ÁíÍâÒ»¸öºÃ´¦ÊÇ¿ÉÒÔ½«²»Í¬µÄÒµÎñÂß¼·Ö²¼µ½²»Í¬µÄ·þÎñÆ÷ÉÏÒÔ½µµÍ¸ºÔØ¡£
ÖµµÃÇìÐÒµÄÊÇ£¬¿çÓòÇëÇóµÄ±ê×¼ÒѾ³ǫ̈£¬Ö÷Á÷ä¯ÀÀÆ÷Ò²ÒѾʵÏÖÁËÕâÒ»±ê×¼¡£W3C ¹¤×÷×éÖÐµÄ Web Applications Working Group£¨Web Ó¦Óù¤×÷×飩·¢²¼ÁËÒ»¸ö Cross-Origin Resource Sharing£¨¿çÓò×ÊÔ´¹²Ïí£¬¸Ã¹æ·¶µØÖ·£ºhttp://www.w3.org/TR/access-control/ºÍhttp: //dev.w3.org/2006/waf/access-control/£© ÍƼö¹æ·¶À´½â¾ö¿çÓòÇëÇóµÄÎÊÌâ¡£¸Ã¹æ·¶ÌṩÁËÒ»ÖÖ¸ü°²È«µÄ¿çÓòÊý¾Ý½»»»·½·¨¡£¾ßÌå¹æ·¶µÄ½éÉÜ¿ÉÒÔ·ÃÎÊÉÏÃæÌṩµÄÍøÕ¾µØÖ·¡£ÖµµÃ×¢ÒâµÄÊÇ£º¸Ã¹æ·¶Ö»ÄÜÓ¦ÓÃÔÚÀàËÆ XMLHttprequest ÕâÑùµÄ API ÈÝÆ÷ÄÚ¡£IE8¡¢Firefox 3.5 ¼°ÆäÒÔºóµÄ°æ±¾¡¢Chromeä¯ÀÀÆ÷¡¢Safari 4 µÈÒѾʵÏÖÁË Cross-Origin Resource Sharing ¹æ·¶£¬ÒѾ¿ÉÒÔ½øÐпçÓòÇëÇóÁË¡£
Cross-Origin Resource Sharing µÄ¹¤×÷·½Ê½ÊÇͨ¹ýÌí¼Ó HTTP Í·µÄ·½·¨À´ÅжÏÄÄЩ×ÊÔ´ÔÊÐí Web ä¯ÀÀÆ÷·ÃÎʸÃÓòÃûϵÄÐÅÏ¢¡£È»¶ø£¬¶ÔÓÚÄÇЩ HTTP ÇëÇóµ¼ÖÂÓû§Êý¾Ý²úÉú¸±×÷ÓõÄÇëÇó·½·¨£¨ÌرðÊǶÔÓÚ³ýÁËGET¡¢Ä³Ð© MIME ÀàÐ굀 POST Ö®ÍâµÄ HTTP·½·¨£©£¬¸Ã¹æ·¶ÒªÇóä¯ÀÀÆ÷¶ÔÇëÇó½øÐГԤÏÈÑ锣¬Í¨¹ý·¢ËÍ HTTP µÄ OPTIONS ÇëÇóͷѯÎÊ·þÎñÆ÷ÓÐÄÄЩ֧³ÖµÄ·½·¨£¬ÔÚÕ÷µÃ·þÎñÆ÷µÄͬÒâºó£¬ÔÙʹÓÃʵ¼ÊµÄ HTTP ÇëÇó·½·¨·¢ËÍʵ¼
Ïà¹ØÎĵµ£º
function selectTradezone(){
var copyTradezone = document.forms[0].copyTradezone;
new BaseTool().ajax("getTradezoneByCity",callback,[document.forms[0].city.value,document.forms[0].brand.value]);
function callba ......
ÏÖÔÚ¸Õ¸Õ¿´Ò»Ð©¹ØÓÚAjaxµÄһЩ֪ʶµã¡£°ÑËüдÏÂÀ´£¬×÷Ϊ֪ʶµÄ±¸Íü¼£¡
ÒÔÏ´¿Êô¸öÈËÀí½â£¡£¡£¡
1. Ajax·ÖΪҳÃ沿·Ö£¨Ç°¶Ë£©£¬ºÍºǫ́´¦Àí²¿·Ö£¨ºó¶Ë£¬servlet£©£»
2. Ò³Ã棺´´½¨XmlHttpRequest¶ÔÏ󣬲»Í¬µÄä¯ÀÀÆ÷£¬ËùÖ§³ÖµÄXmlHttpRequest¶ÔÏó²»Í¨£»
Ò³Ã棺½¨Á¢·¢ ......
<script type="text/javascript">
function addUrl(){
//1¡¢ÉèÖÃÇëÇóurlµØÖ·
var name = document.getElementById("name").value;
var text = document.getElementById("url").value;
var url = "insertUrl.do?name="+name+
"&url="+text+"&time"+new Date() ;
//2¡¢´´½¨xmlHttpRequest¶ÔÏó
x ......
ÆÊÎö AJAX »Ø·¢
ÈôҪʹ ASP.NET Ò³Ãæ³ÉΪ²¿·Ö³ÊÏÖµÄÒ³Ã棬Ê×ÏȱØÐëÏòÒ³ÃæÌí¼ÓÒ»¸ö½Å±¾¹ÜÀíÆ÷£¬È»ºóͨ¹ýʹÓà UpdatePanel ¿Ø¼þ½øÐзâ×°£¬´Ó¶ø¶¨Òå¿É¶ÀÁ¢¸üеÄÇøÓò¡£ÀýÈ磺
< ?xml:namespace prefix = asp />
< asp:ScriptManager runat="server">< /asp:ScriptManager>
< asp:UpdatePanel id=Upda ......
1¡¢µ±¸Ä±ä·þÎñÆ÷ÉϵÄ״̬ʱӦµ±Ê¹ÓÃPOST·½·¨¡£²»Í¬ÓÚGET£¬ÐèÒªÉèÖÃXML- HttpRequest¶ÔÏóµÄContent-TypeÊײ¿£¬ÈçÏÂËùʾ£º
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ÓëGET²»Í¬£¬POST²»»áÏÞÖÆ·¢Ë͸ø·þÎñÆ÷µÄ¾»ºÉµÄ´óС£¬¶øÇÒPOSTÇëÇó²»Äܱ£Ö¤ÊÇÃݵȵġ£
Äã×öµÄ´ó¶àÊýÇëÇó¿ÉÄܶ¼ÊÇG ......