質問編集履歴
5
コメント
title
CHANGED
File without changes
|
body
CHANGED
@@ -146,4 +146,9 @@
|
|
146
146
|
//}
|
147
147
|
|
148
148
|
|
149
|
-
```
|
149
|
+
```
|
150
|
+
|
151
|
+
### 試したこと
|
152
|
+
|
153
|
+
データの送信は確認できました。
|
154
|
+
が取得が上手く出来てないのかphpの変数が空の状態です。
|
4
コード更新
title
CHANGED
File without changes
|
body
CHANGED
@@ -22,61 +22,128 @@
|
|
22
22
|
}
|
23
23
|
add_action( 'wp_head', 'add_my_ajaxurl', 1 );
|
24
24
|
|
25
|
-
function
|
25
|
+
function ajax_move_users() {
|
26
|
+
|
26
|
-
$post = $_POST[
|
27
|
+
$post = $_POST['users_ID'][0];
|
27
|
-
echo $post;
|
28
|
+
echo $post;
|
29
|
+
|
28
|
-
die();
|
30
|
+
die();
|
29
31
|
}
|
30
|
-
add_action(
|
32
|
+
add_action('wp_ajax_ajax_test','ajax_move_users');
|
31
|
-
add_action(
|
33
|
+
add_action('wp_ajax_nopriv_ajax_test','ajax_move_users');
|
32
34
|
|
33
35
|
?>
|
36
|
+
?>
|
34
37
|
```
|
35
38
|
```JavaScriputt
|
39
|
+
|
40
|
+
// var count_log_filename_js ='count_log_js.txt';
|
41
|
+
// var flag='';
|
42
|
+
// var user_id='';
|
43
|
+
|
36
44
|
$(document).ready(function() {
|
45
|
+
|
46
|
+
|
47
|
+
$('button[id=insert_button]').on('click', function() {
|
48
|
+
// flag = 'insert';
|
49
|
+
move('right_list', 'left_list');
|
50
|
+
});
|
51
|
+
|
52
|
+
$('button[id=delete_button]').on('click', function() {
|
53
|
+
// flag = 'delete';
|
54
|
+
move('left_list', 'right_list');
|
55
|
+
});
|
56
|
+
|
57
|
+
var move = function(_this, target) {
|
58
|
+
$('select[id=' + _this + '] option:selected').each(function() {
|
59
|
+
$('select[id=' + target + ']').append($(this).clone());
|
60
|
+
$(this).remove();
|
37
61
|
|
38
|
-
$(‘button[id=insert_button]’).on(‘click’, function() {
|
39
|
-
// flag = ‘insert’;
|
40
|
-
move(‘right_list’, ‘left_list’);
|
41
|
-
});
|
42
62
|
|
43
|
-
$(‘button[id=delete_button]’).on(‘click’, function() {
|
44
|
-
// flag = ‘delete’;
|
45
|
-
move(‘left_list’, ‘right_list’);
|
46
|
-
});
|
63
|
+
});
|
47
64
|
|
48
|
-
var move = function(_this, target) {
|
49
|
-
$(‘select[id=’ + _this + ‘] option:selected’).each(function() {
|
50
|
-
$(‘select[id=’ + target + ‘]’).append($(this).clone());
|
51
|
-
|
65
|
+
};
|
52
66
|
|
53
|
-
var left_list = document.getElementById('left_list');
|
54
|
-
var move_user = $(left_list).text();
|
55
67
|
|
68
|
+
$('button[id=button_a]').on('click', function() {
|
69
|
+
DB_action();
|
70
|
+
});
|
71
|
+
|
72
|
+
var DB_action = function(){
|
73
|
+
|
74
|
+
var left_list = document.getElementById('left_list');
|
75
|
+
var move_users_opsion = $(left_list).children();
|
76
|
+
var move_users = [];
|
77
|
+
|
78
|
+
var max = move_users_opsion.length;
|
79
|
+
for (var i = 0 ; i<max;i++){
|
80
|
+
move_users[i]=move_users_opsion[i].value ;
|
81
|
+
}
|
82
|
+
|
83
|
+
|
84
|
+
var post = 'POST';
|
56
|
-
var postData = {
|
85
|
+
var postData = {
|
57
|
-
'action': '
|
86
|
+
'action': 'ajax_move_users',
|
87
|
+
//action: TOURAJAX_AJAX.action,
|
88
|
+
//nonce: TOURAJAX_AJAX.nonce,
|
89
|
+
users_ID: [move_users]
|
58
|
-
'
|
90
|
+
//'array_test[]': move_user
|
59
|
-
};
|
91
|
+
};
|
92
|
+
|
60
|
-
//
|
93
|
+
//Ajaxで送信
|
61
|
-
$.ajax({
|
94
|
+
$.ajax({
|
62
|
-
url: ajaxurl,
|
95
|
+
url: ajaxurl,
|
63
|
-
|
96
|
+
type: post,
|
64
|
-
dataType:
|
97
|
+
dataType: 'text',
|
65
|
-
data : postData
|
98
|
+
data : postData
|
66
|
-
}).done(function (res) {
|
99
|
+
}).done(function (res) {
|
100
|
+
/*var result_html = "<select>"; //表示用HTML
|
101
|
+
for (date in res){ //配列ループ
|
102
|
+
result_html = result_html +'<option id=' + date + 'name= ' + date '>' + 'aaaaa' + '</option>';
|
103
|
+
}
|
104
|
+
result_html = result_html + "</select>";
|
105
|
+
|
106
|
+
var element = document.getElementById('left_list'); //結果を表示する場所
|
107
|
+
element.innerHTML = result_html; //結果表示*/
|
108
|
+
console.log('送信が成功しました。');
|
67
|
-
|
109
|
+
console.log(postData);
|
68
|
-
}).fail(function (xhr, textStatus, errorThrown) {
|
110
|
+
}).fail(function (xhr, textStatus, errorThrown) {
|
69
|
-
|
111
|
+
alert('エラーが発生しました。');
|
112
|
+
});
|
113
|
+
|
114
|
+
};
|
115
|
+
|
70
116
|
});
|
71
|
-
};
|
72
|
-
});。
|
73
117
|
```
|
74
118
|
```php
|
75
|
-
$button_check = $_GET;
|
76
|
-
$move_user = $_POST;
|
119
|
+
$move_user = $_POST['users_ID'][0];
|
77
|
-
print("<script>
|
78
|
-
move_user.forEach(function(data) {
|
79
|
-
|
120
|
+
global $wpdb;
|
121
|
+
$wpdb->delete( $wpdb->test_master ,
|
122
|
+
array(
|
123
|
+
'posts_ID' => $_SESSION['toukou_id']
|
124
|
+
) ,
|
125
|
+
array(
|
126
|
+
'%d'
|
80
|
-
|
127
|
+
));
|
128
|
+
|
129
|
+
for ($i=0; $i < count($move_user); $i++) {
|
130
|
+
|
131
|
+
global $wpdb;
|
132
|
+
$wpdb->insert( $wpdb->test_master ,
|
133
|
+
array(
|
134
|
+
'posts_ID' => $_SESSION['toukou_id'],
|
135
|
+
'users_ID' => $muve_user[$i]
|
136
|
+
),
|
137
|
+
array(
|
138
|
+
'%d',
|
139
|
+
'%d'
|
140
|
+
));
|
141
|
+
|
142
|
+
}
|
143
|
+
|
81
|
-
|
144
|
+
//if (count($move_user)!==0){
|
145
|
+
print "<script>alert('更新に成功しました。');</script>";
|
146
|
+
//}
|
147
|
+
|
148
|
+
|
82
149
|
```
|
3
コード修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -20,6 +20,7 @@
|
|
20
20
|
</script>
|
21
21
|
<?php
|
22
22
|
}
|
23
|
+
add_action( 'wp_head', 'add_my_ajaxurl', 1 );
|
23
24
|
|
24
25
|
function ajax_test() {
|
25
26
|
$post = $_POST[‘post’];
|
2
コード修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -50,7 +50,7 @@
|
|
50
50
|
$(this).remove();
|
51
51
|
|
52
52
|
var left_list = document.getElementById('left_list');
|
53
|
-
var move_user = $(left_list).
|
53
|
+
var move_user = $(left_list).text();
|
54
54
|
|
55
55
|
var postData = {
|
56
56
|
'action': 'ajax_test',
|
@@ -71,6 +71,11 @@
|
|
71
71
|
});。
|
72
72
|
```
|
73
73
|
```php
|
74
|
+
$button_check = $_GET;
|
74
|
-
$move_user = $_POST
|
75
|
+
$move_user = $_POST;
|
75
|
-
|
76
|
+
print("<script>
|
77
|
+
move_user.forEach(function(data) {
|
78
|
+
alert(data);
|
79
|
+
});
|
80
|
+
</script>");
|
76
81
|
```
|
1
指摘箇所の更新
title
CHANGED
File without changes
|
body
CHANGED
@@ -30,7 +30,7 @@
|
|
30
30
|
add_action(‘wp_ajax_nopriv_ajax_test’,’ajax_test’);
|
31
31
|
|
32
32
|
?>
|
33
|
-
|
33
|
+
```
|
34
34
|
```JavaScriputt
|
35
35
|
$(document).ready(function() {
|
36
36
|
|
@@ -49,13 +49,17 @@
|
|
49
49
|
$(‘select[id=’ + target + ‘]’).append($(this).clone());
|
50
50
|
$(this).remove();
|
51
51
|
|
52
|
+
var left_list = document.getElementById('left_list');
|
53
|
+
var move_user = $(left_list).children();
|
54
|
+
|
52
55
|
var postData = {
|
56
|
+
'action': 'ajax_test',
|
53
|
-
move_user
|
57
|
+
'users_ID[]': move_user
|
54
58
|
};
|
55
59
|
// Ajaxで送信
|
56
60
|
$.ajax({
|
57
61
|
url: ajaxurl,
|
58
|
-
method:
|
62
|
+
method: POST,
|
59
63
|
dataType: ‘text’,
|
60
64
|
data : postData,
|
61
65
|
}).done(function (res) {
|
@@ -65,7 +69,8 @@
|
|
65
69
|
});
|
66
70
|
};
|
67
71
|
});。
|
68
|
-
|
72
|
+
```
|
69
73
|
```php
|
70
74
|
$move_user = $_POST['users_ID']/*json_encode($_POST['users_ID'])*/;
|
71
|
-
print_r ($move_user);
|
75
|
+
print_r ($move_user);
|
76
|
+
```
|