duannv2081 2019-06-17 15:27
浏览 116
已采纳

Ajax ResponseText正在变为true但无法写入div

Ajax Code:

    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 ); 
                        }, 
        });
         }
    });
});

Functions.PHP :

function hesaplayici(){
$id    = (int) $_POST['value'];
$sonucum =  the_field('sertifika_aciklamasi', $id);}

Responsetext show on console but can't write to my div ( id: #xcvb ) Any one can help me about this ?

https://up.uac.ist/images/2019/06/17/Screenshot_2.png https://up.uac.ist/images/2019/06/17/Screenshot_3.png

  • 写回答

2条回答 默认 最新

  • dongtuan8547 2019-06-17 20:30
    关注

    Looks like you have a few things wrong here. First, I'm unsure how you are running jQuery with a PHP echo statement in it. You shouldn't be able to do that. This is the proper way to use Ajax with Wordpress.

    $.ajax({
                type: 'POST',
                url: ajax_object.ajax_url,
                data: {
                    action: 'hesaplama',
                    value: valueSelect
                }, 
                error: function (data) {
                    console.log(data);
                }, 
                success: function (data) {
    
                   console.log(data);
                   if ( data == '') {
                      $('#xcvb').html( '<span>Bu #id: ' +  valueSelect + ' ye ait bir içerik bulunamadı.</span>' );
                   }
                   else {
                      $('#xcvb').append( data );
                   }
    
                }
        });
    
    

    You should try echoing your response.

    function hesaplayici(){
    
    $id = $_POST['value'];
    
    $sonucum =  the_field('sertifika_aciklamasi', $id);
    
    echo $sonucum;
    
    die();
    
    }
    
    add_action( 'wp_ajax_send_hesaplayici', 'hesaplayici' );
    add_action( 'wp_ajax_nopriv_hesaplayici', 'hesaplayici' );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab