Ajax ResponseText 越来越真实但无法写入 div

阿贾克斯代码:


    jQuery(document).ready( function($) {

    var valueCheck;

    $('#acf-field_5cdc07b87c8f8-field_5cdc08405814f').on( 'change', function () {

         valueSelect = $(this).val();

         if ( parseInt ( valueSelect ) > 0 ) {

        $.ajax( ajaxurl, {

            type: 'POST',

            url: '<?php echo admin_url('admin-ajax.php'); ?>',

            data: { action: 'hesaplama', // The name of the WP action

                    value:  valueSelect,       // the dataVAlues

            },

            dataType: 'json',

            success: function ( response ) {     // to develop in case of success

                             if ( response.success ) {

                                  sonucum = response.html;  // Here we get the results of the PHP remote function

                                  $('#xcvb').html( sonucum );

                             }

                             else {

                                  $('#xcvb').html( '<span>Bu #id: ' +  valueSelect + ' ye ait bir içerik bulunamadı.</span>' );

                             }

                        },

            error: function ( errorThrown ) {   // to develop in case of error

                             console.log( errorThrown ); 

                        }, 

        });

         }

    });

});

函数.PHP :


function hesaplayici(){

$id    = (int) $_POST['value'];

$sonucum =  the_field('sertifika_aciklamasi', $id);}

响应文本显示在控制台上,但无法写入我的 div ( id: #xcvb ) 任何人都可以帮助我解决这个问题吗?

http://img.mukewang.com/61283fc800015be809610502.jpg

http://img1.mukewang.com/61283fcf0001e74103390025.jpg

茅侃侃
浏览 145回答 2
2回答

倚天杖

请像这样尝试:在 php 端:$return = ['myvarname' => 'your data here'];echo json_encode($return);exit();&nbsp;在js端:success: function ( response ) {&nbsp;$(#idofyourdiv).html(response.myvarname);}
打开App,查看更多内容
随时随地看视频慕课网APP