尊龙凯时人生就是博

ÔõÑùÔÚThinkPHP6ÖÐʹÓÃAjax¾ÙÐÐÒì²½²Ù×÷£¿

Ëæ×ÅwebÓ¦ÓóÌÐòµÄÒ»Ö±Éú³¤ £¬Ê¹ÓÃajax¾ÙÐÐÒì²½²Ù×÷ÒѾ­³ÉΪÁËweb¿ª·¢µÄ³£¼ûÐèÇó¡£ÔÚthinkphp6¿ò¼ÜÖÐ £¬Í¨¹ýajax¾ÙÐÐÒì²½²Ù×÷Ò²ºÜÊǼòÆÓ¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚthinkphp6ÖÐʹÓÃajax¾ÙÐÐÒì²½²Ù×÷¡£

Ò»¡¢Ê²Ã´ÊÇAjax£¿

AjaxÈ«³ÆΪAsynchrnous JavaScript And XML £¬ÊÇÒ»ÖÖÓÃÓÚ½¨Éè¿ìËÙ¶¯Ì¬WebÒ³ÃæµÄÊÖÒÕ¡£Ajax¿ÉÒÔÔÚ²»ÖØмÓÔØÕû¸öÒ³ÃæµÄÇéÐÎÏ £¬ÊµÏÖÒ³ÃæÊý¾ÝµÄÒì²½¼ÓÔغ͸üС£

ͨ¹ýAjax £¬ÎÒÃÇ¿ÉÒÔÔÚWebÒ³ÃæÖÐʹÓÃJavaScriptÀ´ÏòЧÀÍÆ÷·¢ËÍÇëÇó²¢»ñÈ¡ÏìÓ¦ £¬¶øÎÞÐèË¢ÐÂÕû¸öÒ³Ãæ¡£ÕâʹµÃÒ³Ãæ±äµÃÔ½·¢Á÷ͨ¡¢¿ìËÙ £¬Óû§ÌåÑéÒ²»á¸üºÃ¡£

¶þ¡¢ThinkPHP6ÖеÄAjax

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

ÔÚThinkPHP6¿ò¼ÜÖÐ £¬Ê¹ÓÃAjax¾ÙÐÐÒì²½²Ù×÷ÐèÒª×ñÕÕÒÔÏ°취£º

1.±àдǰ¶ËÒ³Ãæ

Ê×ÏÈ £¬ÎÒÃÇÐèÒªÔÚÇ°¶ËÒ³ÃæÖбàдJavaScript´úÂë £¬ÒÔʵÏÖAjaxÒì²½ÇëÇóµÄ·¢ËͺÍÏìÓ¦´¦Àí¡£ÒÔÒ»¸ö¼òÆÓµÄʾÀýΪÀý £¬ÎÒÃÇ¿ÉÒÔÔÚÒ³ÃæÖмÓÈëÒÔÏ´úÂ룺

<script>
    $(document).ready(function(){
        $("#submitBtn").click(function(){
            $.ajax({
                type: "POST",
                url: "<?php echo url('ajaxtest'); ?>",
                data:{
                    name:$('#name').val(),
                    age:$('#age').val()
                },
                dataType: "json",
                success: function(data){
                    if(data.status==1){
                        alert("ÉúÑÄÀֳɣ¡");
                    }else{
                        alert("ÉúÑÄʧ°Ü£¡");
                    }
                }
            });
        });
    });
</script>

<body>
    <input type="text" name="name" id="name" placeholder="ÇëÊäÈëÐÕÃû">
    <input type="text" name="age" id="age" placeholder="ÇëÊäÈëÄêËê">
    <button id="submitBtn">ÉúÑÄ</button>
</body>

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¶Î´úÂëÖÐ £¬ÎÒÃÇʹÓÃÁËjQueryÖеÄAjaxº¯Êý £¬ÏòЧÀÍÆ÷·¢ËÍÁËÒ»¸öPOSTÇëÇó £¬²¢½«Ìá½»µÄÊý¾Ý×÷ΪÇëÇó²ÎÊýת´ï¸øÁËЧÀÍÆ÷¡£ÇëÇóµÄURLΪajaxtest £¬Õâ¸öURLͨ³£¶ÔÓ¦×ÅÒ»¸ö¿ØÖÆÆ÷µÄÒªÁì¡£Õâ¸öURLµÄÌìÉúÒªÁìʹÓÃÁËThinkPHP6¿ò¼ÜÖÐÌṩµÄurlº¯Êý¡£µ±ÇëÇóÀֳɺó £¬Ð§ÀÍÆ÷»á·µ»ØÒ»¸öJSONÃûÌõÄÊý¾Ý £¬ÎÒÃÇÔÚÏìÓ¦´¦Àíº¯ÊýÖоÙÐÐÁË´¦Àí¡£

2.±àдЧÀͶ˿ØÖÆÆ÷

ΪÁËÏìӦǰ¶ËÒ³ÃæµÄAjaxÇëÇó £¬ÎÒÃÇÐèÒªÔÚЧÀÍÆ÷¶Ë±àд¿ØÖÆÆ÷ÒªÁì¡£ÔÚ¿ØÖÆÆ÷ÒªÁìÖÐ £¬ÎÒÃÇ¿ÉÒÔ¾ÙÐÐÊý¾Ý´¦Àí £¬²¢ÏòÇ°¶ËÒ³Ãæ·µ»ØJSONÃûÌõÄÏìÓ¦Êý¾Ý¡£ÀýÈ磺

public function ajaxtest()
{
    $data = [
        'name' => input('post.name'),
        'age' => input('post.age')
    ];

    //TODO Êý¾Ý´¦Àí

    if(´¦ÀíЧ¹û){
        return json(['status'=>1]);
    }else{
        return json(['status'=>0]);
    }
}

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸ö¿ØÖÆÆ÷ÒªÁìÖÐ £¬ÎÒÃÇÊ×ÏÈ´ÓÇëÇóÖлñÈ¡Ìá½»µÄÊý¾Ý £¬È»ºó¾ÙÐÐÊý¾Ý´¦Àí¡£´¦ÀíÍê±Ïºó £¬Æ¾Ö¤´¦ÀíЧ¹ûÏòÇ°¶ËÒ³Ãæ·µ»Ø²î±ðµÄJSONÏìÓ¦Êý¾Ý¡£

3.·ÓÉÉèÖÃ

×îºó £¬ÎÒÃÇÐèÒªÔÚ¿ò¼ÜµÄ·ÓÉÖÐÉèÖÃÕâ¸öURLµÄ·ÓɹæÔò¡£ÀýÈ磺

Route::post('ajaxtest', 'Test/ajaxtest');

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸ö·ÓɹæÔòÖÐ £¬ÎÒÃǽ«ajaxtestµÄPOSTÇëÇóÓ³Éäµ½ÁËTest¿ØÖÆÆ÷µÄajaxtestÒªÁìÖС£

ÖÁ´Ë £¬ÎÒÃÇÒѾ­Íê³ÉÁËÔÚThinkPHP6ÖÐʹÓÃAjax¾ÙÐÐÒì²½²Ù×÷µÄ°ì·¨¡£

Èý¡¢×ܽá

±¾ÎÄÏÈÈÝÁËÔÚThinkPHP6¿ò¼ÜÖÐʹÓÃAjax¾ÙÐÐÒì²½²Ù×÷µÄÒªÁ졣ͨ¹ýÕâÖÖÒªÁì £¬ÎÒÃÇ¿ÉÒÔÔÚWebÓ¦ÓóÌÐòÖÐʹÓÃAjaxÊÖÒÕ £¬ÊµÏÖÒ³ÃæÊý¾ÝµÄÒì²½¼ÓÔغ͸üР£¬Ìá¸ßWebÓ¦ÓóÌÐòµÄ½»»¥ÐÔºÍÓû§ÌåÑé¡£ÐèҪעÖصÄÊÇ £¬ÔÚʹÓÃAjaxÒì²½²Ù×÷ʱ £¬ÎªÁË°ü¹ÜÊý¾ÝÇå¾² £¬ÎÒÃÇÐèÒª¾ÙÐÐÐëÒªµÄÊý¾ÝÑéÖ¤ºÍ±ÜÃâSQL×¢ÈëµÈÇå¾²²½·¥¡£

ÒÔÉϾÍÊÇÔõÑùÔÚThinkPHP6ÖÐʹÓÃAjax¾ÙÐÐÒì²½²Ù×÷£¿µÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是博

18523999891

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

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

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