阿贾克斯代码: 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);
}
- 2 回答
- 0 关注
- 144 浏览
添加回答
举报
0/150
提交
取消