この質問は多く寄せられていることを知っているので、重複して申し訳ありません。ただし、これを 0 以外の値に戻すことはできないようです。以下は、Twenty-Twelve テーマ内の functions.php の下部に含めたコードです。
add_filter( 'views_edit-destination', 'so_13813805_add_button_to_views' );
function so_13813805_add_button_to_views( $views )
{
$views['my-button'] = '<button id="update-dest-cache" type="button" class="button" title="Update Destinations Cache" style="margin:5px" onclick="updateDestCache()">Update Destinations Cache</button>';
$views['my-button'] .= '
<script type="text/javascript" >
function updateDestCache() {
jQuery.ajax({
type: "POST",
url: ajaxurl,
dataType: "json",
action: "testAjaxFunction",
success: function(response){
alert("Got this from the server: " + response);
},
error: function(MLHttpRequest, textStatus, errorThrown){
alert("There was an error: " + errorThrown);
},
timeout: 60000
});
};
</script>
';
return $views;
}
function testAjax(){
echo "ANYTHING!!!!";
die();
}
add_action('wp_ajax_testAjaxFunction', 'testAjax');
add_action('wp_ajax_nopriv_testAjaxFunction', 'testAjax' );
このコードは、カスタム投稿タイプの編集リストにボタンを追加し、クリックすると関数を実行します。ボタンが表示され、関数が実行され、ajax 関数が呼び出されますが、応答は常に 0 です。
なぜこれが起こり続けるのかについて何か考えはありますか?