AJax¼¼Êõ

WordPressÖÐÀûÓÃAJAXÒì²½»ñÈ¡ÆÀÂÛÓû§Í·ÏñµÄ·½·¨

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2016-01-15 14:13 ÎÒÒªÆÀÂÛ( )

ÕâƪÎÄÕÂÖ÷Òª½éÉÜÁËWordPressÖÐÀûÓÃAJAXÒì²½»ñÈ¡ÆÀÂÛÓû§Í·ÏñµÄ·½·¨,ÎÄÖеÄÀý×ÓÊÇÊäÈëÓÊÏä¼´¿É»ñÈ¡Í·Ïñ,ÐèÒªµÄÅóÓÑ¿ÉÒԲο¼ÏÂ

ÔÚÆÀÂÛÕßÊäÈëÓÊÏäºó£¬Òì²½»ñµÃÆÀÂÛÕßµÄÍ·Ïñ²¢ÏÔʾ³öÀ´£¬¸öÈ˸оõÕâ¸ö¹¦ÄÜËä²»ÄܸøÓû§ÌåÑé´øÀ´¶à´óµÄÌáÉý£¬Ò²²»ËãÊÇÒ»¸öʵÓõŦÄÜ£¬µ«ÖÁÉÙºÜìÅ£¬¿´µ½ÓеÄÍøÕ¾ÓÐÌí¼ÓÕâ¸ö¹¦ÄÜ£¬ÎÒÒ²²»¸Ê¼ÅįËùÒÔҲдÁ˸ö½Å±¾£¬Ã»ÓÐʱ¼ä×ö·â×°£¬ËùÒÔÖ±½ÓÉÏÔ­ÀíºÍ´úÂë¡£

Òì²½¶¯Ì¬µ÷ÓÃÍ·ÏñÔ­Àí

òËƺܶಽÖ裬ÆäʵºÜ¼òµ¥£¬ÎÒÃÇÖ»Òª½«×Ô¼ºµÄÖ÷ÌâÉÔ×÷Ð޸ľͿÉÒÔµ½´ïЧ¹û¡£

¼òµ¥¹¦ÄܽØͼ£º

201618171924137.jpg (519¡Á388)

ʵÏÖ

¹¦ÄÜ´úÂ룺JavaScript
ÒÔÏ´úÂëÐ輯³É JQuery ¿ò¼ÜÖС£
apiurl ±äÁ¿ÎªÄãµÄphp api ½Ó¿ÚÎļþµØÖ·£¬Îļþ´úÂëÏÂÃæÓС£
¹¦ÄÜÖ÷Òª¼¯ÖÐÔÚemailÊäÈë¿òʧȥ½¹µãµÄ¶¯×÷ÉÏ¡£

function getAvatar(authorEmail) {//»ñµÃÍ·Ïñ´úÂë·â×°º¯Êý var nowtime = Math.round(new Date().getTime() / 1000); $.get(apiurl, { action : "get_avatar", email : authorEmail, t : nowtime }, function(data) { $('#get-avatar-img').fadeOut('slow', function() { $('#get-avatar-img').html(data).fadeIn(); }) }); } var avatarhtml = '<div>'; avatarhtml += '</div>'; $('#respond').append(avatarhtml);//Ìí¼ÓÍ·ÏñHTML if($('#email').val().length > 1) getAvatar($('#email').val());//»ñµÃÓÊÏäµØÖ· $('#email').focusout(function() {//emailÊäÈë¿òʧȥ½¹µã°ó¶¨µÄ¶¯×÷ var authorEmail = $('#email').val(); var pattern = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/; var flag = pattern.test(authorEmail); if(flag) { $('#get-avatar-img').html('ÔØÈëÍ·ÏñÖÐ').fadeIn('fast'); getAvatar(authorEmail); } else { alert('ÇëÊäÈëÕýÈ·ÓÊÏäµØÖ·'); } })

¹¦ÄÜ´úÂ룺PHP
ºǫ́ÏìÓ¦´úÂ룬ÔÚÕâÀïÎÒÓÃÁËÒ»¸öµ¥¶ÀµÄÒ³ÃæÎļþÀ´×öÏìÓ¦£¬
ÕâÑù×öµÄºÃ´¦ÊDz»Óôò¿ªÃ¿¸öÒ³ÃæµÄʱºò¶¼È¥µ÷ÓÃÕⲿ·Ö´úÂ룬
Ö»ÊÇÔÚ×ö³öÇëÇóʱ²ÅÈ¥ÏìÓ¦£¬ÕâÑù×ö¿ÉÒÔÍêÈ«ÞðÆúÖ÷ÌâµÄÏòºó¼æÈݹËÂÇ¡£
µ±È»ÄãÒ²¿ÉÒÔ½«ÏìÓ¦º¯Êý¹ÒÔص½wpµÄhookÉÏ¡£

$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : false ; if($action){//ÁôÏÂÒÔºóÌí¼Ó¹¦ÄܵĿռ䣬Ä㶮µÄ¡£ switch ($action) { case 'get_avatar': $email = isset($_REQUEST['email']) ? $_REQUEST['email']: false ; if($email){ echo get_avatar($email,60); } break; default: echo "ÇëÇóÄÚÈݲ»³ä·Ö"; break; } }

×ܽá
So¡­¡­. ºÜ¼òµ¥°É£¿
ÇëÇó-> ÏìÓ¦ -> Ìí¼Ó ×ܹ²Èý²½Çú¡£
µ±È»£¬ÕâÀïΪÁËÔöÇ¿Âß¼­ÐÔ£¬Í»³öÌõÀí£¬°ÑһЩ±ØÒªµÄÊý¾Ý¹ýÂË£¬
»¹ÓÐһЩ´íÎóÅжϣ¬ÕâЩ¾ÍËãÊÇÁô×÷˼¿¼°É¡£

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
  • JQueryʵÏÖAjax¼ÓÔØͼƬµÄ·½·¨

    JQueryʵÏÖAjax¼ÓÔØͼƬµÄ·½·¨

    2016-02-24 17:01

  • ÅжÏÓû§ÊDz»ÊÇΪajaxÇëÇó

    ÅжÏÓû§ÊDz»ÊÇΪajaxÇëÇó

    2016-02-24 17:00

  • AjaxÓëWEB¿ª·¢ by alixixi.com

    AjaxÓëWEB¿ª·¢ by alixixi.com

    2016-02-11 11:02

  • jQuery.ajax()µÄÏà¹Ø²ÎÊý¼°Ê¹ÓÃ

    jQuery.ajax()µÄÏà¹Ø²ÎÊý¼°Ê¹ÓÃ

    2016-02-08 16:00

ÍøÓѵãÆÀ
Ö