JQuery AJAXÌá½»ÖÐÎÄÂÒÂëµÄ½â¾ö·½°¸
×÷Õߣº ×ÖÌ壺[ ] ÀàÐÍ£º×ªÔØ Ê±¼ä£º2010-07-02
JQueryÊÇÒ»¸ö·Ç³£ÓÅÐãµÄ¿ò¼Ü£¬ÔÚÌض¨³¡ºÏÏÂʹÓÃJQueryÌá½»Êý¾Ý£¬Ï൱µÄ·½±ã¿ì½Ý¡£ µ«ÊÇ£¬ÔÚ´¦ÀíÒ»¸öGB2312±àÂëµÄÍøÕ¾AJAXÌύʱ£¬ÖÐÎÄÊý¾ÝÈ´³ÉÁËÂÒÂë¡£
ÏÖÏóÈçÏ£º
1£©ÔÚFirefoxÏ£¬´¦ÀíÒ³ÃæµÄ±àÂëΪgb2312£¬Ìá½»Êý¾ÝûÓÐÎÊÌ⣬ÖÐÎÄÄܹ»ÕýÈ·½âÎö£»
2£©ÔÚIE8Ï£¬´¦ÀíÒ³ÃæµÄ±àÂëΪgb2312£¬Ìá½»ÖÐÎÄÊý¾Ý³öÏÖÂÒÂë¡£
ÎÞÂÛÊÇ$.post»¹ÊÇ$.ajax£¬ÒÖ»ò$.ajaxSubmit£¨À´×ÔÓÚForm²å¼þ£©£¬ÔÚ֮ǰµÄUTF-8±àÂëµÄÍøÕ¾¶¼Ã»ÓгöÏÖ¹ýÈκÎÎÊÌ⣬ ¿´À´ÊÇÓÉÓÚÌá½»Êý¾ÝµÄÍøÒ³µÄ±àÂë¸ñʽÔì³ÉµÄÁË¡£²»¹ÜÔõôÑù£¬¼ÈÈ»ÊÇä¯ÀÀÆ÷Ö®¼ä´æÔÚ²îÒ죬»¹ÊÇ´ÓHTTP°üÀ´¿´ÓÐʲôÎÊÌâ°É¡£
´ò¿ªFiddle£¬·Ö±ðÓÃFirefoxºÍIE×öÒ»¸öAJAXÌá½»£¨ÒÔÓû§µÇ¼ΪÀý£©£¬¼ì²éËûÃǵÄHTTPÍ·£¬·¢ÏÖ
1£©Á½¸öä¯ÀÀÆ÷Ìá½»µÄFormÊý¾ÝÊÇÒ»Öµģ¬¶¼ÊǽøÐÐÁËUTF-8µÄ±àÂ룬ÈçÏÂͼËùʾ¡£
·ÖÎö£ºJQueryµÄAJAXÌá½»£¬»á½«ÒªÌá½»µÄÊý¾Ý½øÐбàÂ룬ʹÓÃencodeURIComponentÔÚjsÖд¦ÀíÊý¾Ý¡£Òò´Ë£¬ÎÞÂÛÊÇ Firefox»òÕßIE£¬Ìá½»µÄÊý¾Ý¶¼ÊÇÒ»Öµģ¬¶¼ÊÇUTF-8±àÂëºóµÄÊý¾Ý¡£
2£©²é¿´Header£¬·¢ÏÖEntityÖеÄContent-Type´æÔÚ²îÒì
ÔÚFirefoxÖУ¬Content-TypeÖ¸¶¨ÁË×Ö·û¼¯Îªutf-8¡£
¶øÔÚIE8ÖУ¬È´Ã»ÓÐÈκεÄ×Ö·û¼¯Ö¸¶¨¡£
·ÖÎö£ºÏÔÈ»£¬Ä¬ÈÏÇé¿öÏ£¬AJAXµÄÒì²½Ìá½»µÄ×Ö·û±àÂëÓ¦¸ÃºÍÍøÒ³±¾Éí±£³ÖÒ»Ö£¬Ò²¾ÍÊÇ˵£¬Server¶ËÔÚûÓз¢ÏÖÏÔʾµÄcharsetÖ¸¶¨µÄÇé ¿öÏ£¬Ê¹ÓÃgb2312À´½âÂëÊý¾Ý£¨µ«ÊÇÊý¾ÝÔÚÌύǰÒѾ±»UTF-8±àÂëÁË£©£¬Õâ¾ÍÊÇΪʲôÔÚIEÏ»á³öÏÖÂÒÂëµÄ¸ùÔ´£¬¶øÔÚFirefoxÏ£¬ä¯ÀÀÆ÷ÔÚ Ìá½»AJAXÊý¾ÝµÄʱºò£¬¼ÓÉÏÁËcharsetµÄÏÔʾָ¶¨£¬µ¼ÖÂServer¶Ë²ÉÓÃUTF-8À´½âÂëÊý¾Ý£¨ÕýÈ·½âÂ룩¡£
Íƶϣº¿´À´Òª½â¾öÕâ¸öÖÐÎÄÂÒÂëÎÊÌ⣬¾Í±ØÐë¸øAJAXÒì²½Ìá½»Ö¸¶¨ÏÔ Ê¾µÄcharset£¡
ÂíÉϲéÔÄJQueryµÄAJAX¹¤¾ßº¯ÊýµÄ˵Ã÷£¬·¢ÏÖoptionsÖÐÓÐÒ»¸öÖ¸¶¨content-typeµÄ²ÎÊý£¬¸øÎÒµÄAJAX´úÂë¼ÓÉÏ£º
¸´ÖÆ´úÂë ´úÂëÈçÏÂ:
jQuery(form).ajaxSubmit({
url: "ajax.aspx?a=memberlogin",
type: "post",
dataType: "json",
contentType: "application/x-www-form-urlencoded; charset=utf-8",
success: showLoginResponse
});
²âÊÔ£¬OK£¡£¡£¡
Äú¿ÉÄܸÐÐËȤµÄÎÄÕÂ:
Tags£º
Ïà¹ØÎÄÕÂ
×îÐÂÆÀÂÛ
¡¡