プラグインを作成しており、ウィジェットにはドロップダウン リストが含まれており、前のドロップダウン リストの選択値に基づいて AJAX を使用してデータベースから連続する各ドロップダウン リストの値を取得する必要があります。
ここにある WordPress コーデックスのコードを少し変更したバージョンを使用します: http://codex.wordpress.org/AJAX_in_Plugins
何らかの理由で、アクション関数が呼び出されていないか、コードにエラーがあります:
// add action hooks
add_action('wp_footer', 'er_qm_ajax_handler' );
add_action('wp_ajax_repopulate_widget_club_type', 'repopulate_widget_club_type');
add_action('wp_ajax_nopriv_repopulate_widget_club_type', 'repopulate_widget_club_type');
// action for the wp_footer hook to insert the javascript
function er_qm_ajax_handler(){
?>
<script type="text/javascript" >
jQuery(document).ready(function($) {
jQuery('#widget_manufacturer').val('3').change(function(){
var manufacturer = $("#widget_manufacturer").val();
var data = {
action: 'repopulate_widget_club_type',
selected_manufacturer: manufacturer
};
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
jQuery.post(ajaxurl, data, function(response) {
alert('Got this from the server: ' + response);
});
});
});
</script>
<?php
}
// The action function
function repopulate_widget_club_type(){
die("Got to the action");
}
AJAX投稿から応答が得られないため、何が間違っているのか正確にはわかりません.ドロップダウンリストを変更したら、テストするためにいくつかのアラート()を設定したため、jQuery .change()が機能していることを知っています値。
どんな考えや助けも大歓迎です、ありがとう!