为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
茅侃侃 2021-08-27 09:28:07
阿贾克斯代码:    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 ) 任何人都可以帮助我解决这个问题吗?
查看完整描述

2 回答

?
倚天杖

TA贡献1828条经验 获得超3个赞

请像这样尝试:


在 php 端:


$return = ['myvarname' => 'your data here'];

echo json_encode($return);

exit(); 

在js端:


success: function ( response ) { 

$(#idofyourdiv).html(response.myvarname);

}


查看完整回答
反对 回复 2021-08-27
  • 2 回答
  • 0 关注
  • 144 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信