thinkphpÔõôʵÏÖÒ³ÃæµÄË¢ÐÂ
Ò»¡¢Ò³ÃæˢеĻù±¾¼ÄÒå
ÔÚÍøÕ¾¿ª·¢Àú³ÌÖУ¬Ò³ÃæË¢ÐÂͨ³£ÊÇÖ¸»ùÓÚÄ¿½ñÒ³ÃæÖØмÓÔØÒ³Ã档ˢкó£¬ÖØлñÈ¡Êý¾Ý£¬¸üÐÂÒ³Ãæչʾ¡£Ò³ÃæË¢ÐÂÒ»Ñùƽ³£·ÖΪÁ½Àࣺǰ¶Ëˢкͺó¶ËˢС£
Ë¢ÐÂÇ°¶ËÒ³Ãæ¿ÉÒÔͨ¹ýÇ°¶ËÊÖÒÕ£¬ºÃ±ÈJavaScript¡¢HTMLºÍCSS£¬ÊµÏÖÒ³ÃæÊÖ¶¯»ò×Ô¶¯Ë¢Ð¡£ÊµÏÖºó¶ËË¢ÐÂͨ³£ÐèÒª±àдºó¶Ë¾ç±¾»òÔËÓÃajaxµÈÊÖÒÕ£¬ÔÚЧÀÍÆ÷¶Ë¾ÙÐвÙ×÷¡£
¶þ¡¢thinkphpÖÐÇ°¶ËË¢ÐÂʵÏÖÒªÁì
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
ÔÚthinkphpÖÐʵÏÖÇ°¶ËˢоÍÏ൱¼òÆÓÁË¡£ÓÃjQueryµÄload()ÒªÁì¾ÍÄÜʵÏÖ¾Ö²¿Ë¢Ð¡£
<script type="text/javascript"> $(document).ready(function() { $("#refreshBtn").click(function(){ $("#data").load(location.href+" #data>*",""); }); }); </script>
µÇ¼ºó¸´ÖÆ
ÐèҪˢÐÂÇøÓòµÄidΪdata£¬Ë¢Ð°´Å¥µÄidΪrefreshBtn¡£µã»÷ˢа´Å¥ºó£¬Í¨¹ýjQueryµÄload()ÒªÁ죬ÖØлñÈ¡Ä¿½ñurlÖÐdataÇøÓòµÄÄÚÈÝ£¬²¢ÇÒ½«ÆäÏÔʾÔÚÒ³ÃæÖУ¬´Ó¶øʵÏÖÒ³ÃæµÄˢС£
Èý¡¢thinkphpÖкó¶ËË¢ÐÂʵÏÖÒªÁì
ÔÚthinkphpÖÐʵÏÖºó¶ËˢУ¬¿ÉÒÔʹÓÃÁ½ÖÖÒªÁìʵÏÖ£º
1.ʹÓÃÔÉúPHPµÄheader()º¯Êý
ͨ¹ýheader()º¯Êý½«Ò³ÃæÖض¨Ïòµ½Ä¿½ñÒ³Ã棬´Ó¶øʵÏÖÒ³ÃæµÄˢС£
header("Location:".$_SERVER['REQUEST_URI']);
µÇ¼ºó¸´ÖÆ
ÕâÀïʹÓÃÁË$_SERVER[‘REQUEST_URI’]»ñÈ¡ÁËÄ¿½ñÇëÇóµÄurl·¾¶£¬´Ó¶øʵÏÖÁËÒ³ÃæµÄÖض¨Ïò£¬ÊµÏÖÁËÒ³ÃæµÄˢС£
2.ʹÓÃthinkphp·â×°µÄredirect()º¯Êý
redirect()º¯ÊýÊÇthinkphp·â×°µÄÒ³ÃæÌøתº¯Êý£¬¿ÉÒÔʵÏÖÒ³ÃæµÄÖض¨ÏòºÍÒ³Ãæ²ÎÊýת´ïµÈ¹¦Ð§¡£
return $this->redirect($_SERVER['REQUEST_URI']);
µÇ¼ºó¸´ÖÆ
ÔÚ´Ë´¦Ê¹ÓÃÁËthinkphp·â×°µÄredirect()º¯Êý£¬À´ÊµÏÖÒ³ÃæµÄˢС£»¹¿ÉÒÔƾ֤ÐèҪת´ïparams²ÎÊý£¬ÒÔ´¦Öóͷ£Ìض¨µÄÓªÒµÂß¼¡£
ËÄ¡¢³£¼ûÎÊÌâÓë½â¾öÒªÁì
ˢкó·ºÆðÖظ´Ìá½»ÎÊÌâ
·ºÆðÕâÖÖÎÊÌâµÄÖ÷ÒªÔµ¹ÊÔÓÉÊÇÓÉÓÚÓû§ÔÚÌá½»±íµ¥Ê±£¬ä¯ÀÀÆ÷½«±íµ¥Êý¾Ý´æ´¢ÔÚ»º´æÖУ¬µ±Óû§Ë¢ÐÂÒ³Ãæʱ£¬ä¯ÀÀÆ÷½«»á×Ô¶¯Öظ´Ìá½»±íµ¥Êý¾Ý¡£
±íµ¥µÄTokenÑéÖ¤¿ÉÒÔͨ¹ýʹÓÃCookie»òSessionÀ´ÊµÏÖ¡£ÏêϸҪÁì¿ÉÒԲο¼CSRF¹¥»÷Óë·ÀÓù¡£
ajaxË¢ÐÂÒ³ÃæÎÞЧ
·ºÆðÕâÖÖÎÊÌâµÄÔµ¹ÊÔÓÉ¿ÉÄÜÊÇajaxµÄ»º´æ»úÖƵ¼ÖÂÒ³ÃæÎÞ·¨Ë¢Ð¡£
½â¾öÒªÁ죺ÔÚajaxÇëÇóÖмÓÈëcache: falseÊôÐÔ£¬Õ¥È¡ajax»º´æ¡£
ÒÔÉϾÍÊÇthinkphpÔõôʵÏÖÒ³ÃæµÄˢеÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡