ajaxの設定方法について
-
ajaxのコーディングですが、下記の様に作成しましたがうまく起動しません。
何処が間違っているか教えていただけないでしょうか。
やりたい事はある2このリストの値を移動させてその値をPOSTで自作のphpに渡したいです。functions.php
function add_my_ajaxurl() {
?>
<script>
var ajaxurl = ‘<?php echo admin_url( ‘admin-ajax.php’); ?>’;
</script>
<?php
}function ajax_test() {
$post = $_POST[‘post’];
echo $post;
die();
}
add_action(‘wp_ajax_ajax_test’,’ajax_test’);
add_action(‘wp_ajax_nopriv_ajax_test’,’ajax_test’);?>
自作php
$(document).ready(function() {$(‘button[id=insert_button]’).on(‘click’, function() {
// flag = ‘insert’;
move(‘right_list’, ‘left_list’);
});$(‘button[id=delete_button]’).on(‘click’, function() {
// flag = ‘delete’;
move(‘left_list’, ‘right_list’);
});var move = function(_this, target) {
$(‘select[id=’ + _this + ‘] option:selected’).each(function() {
$(‘select[id=’ + target + ‘]’).append($(this).clone());
$(this).remove();var postData = {
move_user
};
// Ajaxで送信
$.ajax({
url: ajaxurl,
method: post,
dataType: ‘text’,
data : postData,
}).done(function (res) {
$(‘body’).append(res);
}).fail(function (xhr, textStatus, errorThrown) {
console.log(“NG:” + xhr.status);
});
};
});
- トピック「ajaxの設定方法について」には新たに返信することはできません。