Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Can';显示ajax结果WordPress_Php_Jquery_Ajax_Wordpress - Fatal编程技术网

Php Can';显示ajax结果WordPress

Php Can';显示ajax结果WordPress,php,jquery,ajax,wordpress,Php,Jquery,Ajax,Wordpress,我有以下简单的HTML结构 <button class="aardappel" value="im a value">HENK!</button> <p class="leeg" value="niks"></p> 这就是ajax正在调用的函数 add_action( 'wp_ajax_test_printer', 'test_printer' ); add_action( 'wp_ajax_nopriv_test_printer', 'test

我有以下简单的HTML结构

<button class="aardappel" value="im a value">HENK!</button>
<p class="leeg" value="niks"></p>
这就是ajax正在调用的函数

add_action( 'wp_ajax_test_printer', 'test_printer' );
add_action( 'wp_ajax_nopriv_test_printer', 'test_printer' );
function test_printer()
{
    $result = <<<HTML

    <p>{$_POST["buttonvalue"]}</p>

HTML;

    echo $result;
    exit();
}
add_动作('wp_-ajax_-test_-printer','test_-printer');
添加操作(“wp\u ajax\u nopriv\u test\u printer”、“test\u printer”);
功能测试\u打印机()
{

$result=尝试此脚本。键入错误。它是
成功
函数而不是
成功

<script>
    jQuery(".aardappel").on("click", function(){
        jQuery.ajax({
            url : ajax_testing.ajaxurl,
            data: {
                action      : "test_printer",
                buttonvalue : jQuery(this).val()
            },
            type: "POST",
            //dataType: "html",
            success: function(data){
                console.log(data);
                //jQuery(".leeg").html(data);
            },
            error: function(){
                console.log("foutje");
            },
            completed: function(){
                console.log("doe ik iets?");
            }
        });
    });

</script>

jQuery(“.aardappel”).on(“单击”,函数(){
jQuery.ajax({
url:ajax_testing.ajaxurl,
数据:{
操作:“测试打印机”,
buttonvalue:jQuery(this.val())
},
类型:“POST”,
//数据类型:“html”,
成功:功能(数据){
控制台日志(数据);
//jQuery(“.leeg”).html(数据);
},
错误:函数(){
控制台日志(“foutje”);
},
已完成:函数(){
日志(“doe ik iets?”);
}
});
});

很高兴帮助您:)
<script>
    jQuery(".aardappel").on("click", function(){
        jQuery.ajax({
            url : ajax_testing.ajaxurl,
            data: {
                action      : "test_printer",
                buttonvalue : jQuery(this).val()
            },
            type: "POST",
            //dataType: "html",
            success: function(data){
                console.log(data);
                //jQuery(".leeg").html(data);
            },
            error: function(){
                console.log("foutje");
            },
            completed: function(){
                console.log("doe ik iets?");
            }
        });
    });

</script>