×ðÁú¿­Ê±

thinkphpͼƬ¿çÓò²»ÏÔʾÎÊÌâÔõÑù½â¾ö

Ê×ÏÈ £¬ÈÃÎÒÃÇÏàʶ¿çÓòÊÇʲô¡£¿çÓò±¬·¢ÔÚÁ½¸ö²î±ðÓòÃûµÄÍøÕ¾Ö®¼äµ±Ò»¸öÍøÕ¾µÄ×ÊÔ´ÈçJS¡¢CSS¡¢Ajax»òÕßͼƬµÈÇëÇó»á¼ûÁíÒ»¸öÍøÕ¾µÄ×ÊԴʱ £¬ÓÉÓÚͬԴսÂÔµÄÏÞÖƶø±»×èÖ¹¡£ÏÞÖÆÒ»¸öÍøÕ¾Ö»ÄÜ»á¼ûÓëÆä×ÔÉíÓµÓÐÏàͬÓòÃû¡¢Ð­æźͶ˿ڵÄ×ÊÔ´ÊÇͬԴսÂÔµÄÒ»¸öÒªº¦Çå¾²ÌØÕ÷¡£

ÎÒÃÇÔÚÏîÄ¿ÖÐʹÓÃÁËÒ»¸öµÚÈý·½¿âÀ´¼ÓÔØͼƬ £¬¸Ã¿â½ÓÄÉÁ˾ßÓвî±ðÓòÃûµÄµØµãÀ´´æ´¢Í¼Æ¬¡£Òò´Ë £¬ÔÚä¯ÀÀÆ÷ÖÐ £¬Í¼Æ¬¿çÓòʱÎÞ·¨Õý³£ÏÔʾ¡£

ΪÏàʶ¾öÕâ¸öÎÊÌâ £¬ÎÒÃÇÐèÒªÔÚЧÀÍÆ÷¶Ë¾ÙÐÐһЩÉèÖá£×î³£¼ûµÄ½â¾öÒªÁìÊÇÔÚЧÀÍÆ÷¶ËÉèÖÃCORS£¨¿çÔ´×ÊÔ´¹²Ïí£©¡£CORSʹµÃЧÀÍÆ÷¿ÉÒÔÔÚÏìÓ¦¿Í»§¶ËÇëÇóʱ £¬ÏÞÖÆÖ»ÓÐÌض¨µÄÓòÃû¿ÉÒÔ»á¼û¸Ã×ÊÔ´¡£

ÔÚThinkPHP¿ò¼ÜÖÐ £¬ÎÒÃÇ¿ÉÒÔͨ¹ýÔÚindex.phpÎļþÖÐÌí¼ÓÒÔÏ´úÂëÀ´ÊµÏÖCORS£º

Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»

header('Access-Control-Allow-Origin:*'); //ÔÊÐíËùÓÐȪԴ»á¼û
header('Access-Control-Allow-Method:POST,GET'); //ÔÊÐí»á¼ûµÄ·½·¨

µÇ¼ºó¸´ÖÆ

Õâ¶Î´úÂëÔÊÐíËùÓÐȪԴ»á¼û×ÊÔ´ £¬²¢ÇÒÔÊÐíPOSTºÍGET·½·¨µÄ»á¼û¡£

ÔÚÕâÀïҪעÖصÄÊÇ £¬Õâ¶Î´úÂëÓ¦¸Ã·ÅÔÚindex.phpµÄ¶¥²¿ £¬ÕâÑùËùÓеÄÇëÇó¶¼ÄÜʹÓøÃÉèÖá£

³ýÁËÉèÖÃCORS £¬ÎÒÃÇ»¹¿ÉÒÔʹÓÃÆäËûÒªÁìÀ´½â¾ö¿çÓòÎÊÌâ¡£ÀýÈçJSONP£¨JSON with Padding£© £¬ËüÊÇÒ»ÖÖ½â¾ö¿çÓòµÄ¿ÉÐÐÒªÁì £¬Í¨¹ýÔÚÒ³ÃæÖÐÌí¼ÓÒ»¸öscript±êÇ© £¬½«ÐèÒª»á¼ûµÄÊý¾Ý°ü×°³ÉÒ»¸öº¯Êý £¬È»ºóÔÚÁíÒ»¸öÍøÕ¾ÉÏÎüÊÕ·µ»ØµÄЧ¹û¡£

ÔÚThinkPHP¿ò¼ÜÖÐ £¬ÎÒÃÇ¿ÉÒÔʹÓÃÈçÏ´úÂëÀ´ÌìÉúJSONPÒªÁ죺

$callback = isset($_GET['callback']) ? $_GET['callback'] : 'callback';
$data = array('name' => 'test', 'age' => 18);
echo $callback . '(' . json_encode($data) . ')';

µÇ¼ºó¸´ÖÆ

ÎÒÃÇÏÈÉó²éGET²ÎÊýÊÇ·ñÓÐcallback²ÎÊý £¬ÈôÓÐ £¬ÔòÓøòÎÊý×÷Ϊº¯ÊýÃû¡£½Ó×Å £¬½«Ðè·µ»ØµÄÊý¾Ýת»»³ÉJSONÃûÌà £¬ÔÙ½«ÆäÌí¼Óµ½»Øµ÷º¯ÊýÖС£×îºó £¬ÔÚ·µ»ØÊý¾Ýʱ £¬ÎÒÃǽ«º¯ÊýºÍÊý¾ÝÒ»Æ𷵻ظøä¯ÀÀÆ÷¡£

ÒÔÉϾÍÊÇthinkphpͼƬ¿çÓò²»ÏÔʾÎÊÌâÔõÑù½â¾öµÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±ÊµÊ±ÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
¡¾ÍøÕ¾µØͼ¡¿¡¾sitemap¡¿