質問編集履歴
5
コメント
test
CHANGED
File without changes
|
test
CHANGED
@@ -295,3 +295,13 @@
|
|
295
295
|
|
296
296
|
|
297
297
|
```
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
### 試したこと
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
データの送信は確認できました。
|
306
|
+
|
307
|
+
が取得が上手く出来てないのかphpの変数が空の状態です。
|
4
コード更新
test
CHANGED
File without changes
|
test
CHANGED
@@ -46,118 +46,252 @@
|
|
46
46
|
|
47
47
|
|
48
48
|
|
49
|
-
function ajax_
|
49
|
+
function ajax_move_users() {
|
50
|
-
|
50
|
+
|
51
|
+
|
52
|
+
|
51
|
-
$post = $_POST[
|
53
|
+
$post = $_POST['users_ID'][0];
|
52
|
-
|
54
|
+
|
53
|
-
echo $post;
|
55
|
+
echo $post;
|
54
|
-
|
56
|
+
|
57
|
+
|
58
|
+
|
55
|
-
die();
|
59
|
+
die();
|
56
60
|
|
57
61
|
}
|
58
62
|
|
59
|
-
add_action(
|
63
|
+
add_action('wp_ajax_ajax_test','ajax_move_users');
|
60
|
-
|
64
|
+
|
61
|
-
add_action(
|
65
|
+
add_action('wp_ajax_nopriv_ajax_test','ajax_move_users');
|
62
66
|
|
63
67
|
|
64
68
|
|
65
69
|
?>
|
66
70
|
|
71
|
+
?>
|
72
|
+
|
67
73
|
```
|
68
74
|
|
69
75
|
```JavaScriputt
|
70
76
|
|
77
|
+
|
78
|
+
|
79
|
+
// var count_log_filename_js ='count_log_js.txt';
|
80
|
+
|
81
|
+
// var flag='';
|
82
|
+
|
83
|
+
// var user_id='';
|
84
|
+
|
85
|
+
|
86
|
+
|
71
87
|
$(document).ready(function() {
|
72
88
|
|
73
|
-
|
74
|
-
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
75
|
-
$(
|
93
|
+
$('button[id=insert_button]').on('click', function() {
|
76
|
-
|
94
|
+
|
77
|
-
// flag =
|
95
|
+
// flag = 'insert';
|
78
|
-
|
96
|
+
|
79
|
-
move(
|
97
|
+
move('right_list', 'left_list');
|
98
|
+
|
99
|
+
});
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
$('button[id=delete_button]').on('click', function() {
|
104
|
+
|
105
|
+
// flag = 'delete';
|
106
|
+
|
107
|
+
move('left_list', 'right_list');
|
108
|
+
|
109
|
+
});
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
var move = function(_this, target) {
|
114
|
+
|
115
|
+
$('select[id=' + _this + '] option:selected').each(function() {
|
116
|
+
|
117
|
+
$('select[id=' + target + ']').append($(this).clone());
|
118
|
+
|
119
|
+
$(this).remove();
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
});
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
};
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
$('button[id=button_a]').on('click', function() {
|
136
|
+
|
137
|
+
DB_action();
|
138
|
+
|
139
|
+
});
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
var DB_action = function(){
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
var left_list = document.getElementById('left_list');
|
148
|
+
|
149
|
+
var move_users_opsion = $(left_list).children();
|
150
|
+
|
151
|
+
var move_users = [];
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
var max = move_users_opsion.length;
|
156
|
+
|
157
|
+
for (var i = 0 ; i<max;i++){
|
158
|
+
|
159
|
+
move_users[i]=move_users_opsion[i].value ;
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
var post = 'POST';
|
168
|
+
|
169
|
+
var postData = {
|
170
|
+
|
171
|
+
'action': 'ajax_move_users',
|
172
|
+
|
173
|
+
//action: TOURAJAX_AJAX.action,
|
174
|
+
|
175
|
+
//nonce: TOURAJAX_AJAX.nonce,
|
176
|
+
|
177
|
+
users_ID: [move_users]
|
178
|
+
|
179
|
+
//'array_test[]': move_user
|
180
|
+
|
181
|
+
};
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
//Ajaxで送信
|
186
|
+
|
187
|
+
$.ajax({
|
188
|
+
|
189
|
+
url: ajaxurl,
|
190
|
+
|
191
|
+
type: post,
|
192
|
+
|
193
|
+
dataType: 'text',
|
194
|
+
|
195
|
+
data : postData
|
196
|
+
|
197
|
+
}).done(function (res) {
|
198
|
+
|
199
|
+
/*var result_html = "<select>"; //表示用HTML
|
200
|
+
|
201
|
+
for (date in res){ //配列ループ
|
202
|
+
|
203
|
+
result_html = result_html +'<option id=' + date + 'name= ' + date '>' + 'aaaaa' + '</option>';
|
204
|
+
|
205
|
+
}
|
206
|
+
|
207
|
+
result_html = result_html + "</select>";
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
var element = document.getElementById('left_list'); //結果を表示する場所
|
212
|
+
|
213
|
+
element.innerHTML = result_html; //結果表示*/
|
214
|
+
|
215
|
+
console.log('送信が成功しました。');
|
216
|
+
|
217
|
+
console.log(postData);
|
218
|
+
|
219
|
+
}).fail(function (xhr, textStatus, errorThrown) {
|
220
|
+
|
221
|
+
alert('エラーが発生しました。');
|
222
|
+
|
223
|
+
});
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
};
|
228
|
+
|
229
|
+
|
80
230
|
|
81
231
|
});
|
82
232
|
|
83
|
-
|
84
|
-
|
85
|
-
$(‘button[id=delete_button]’).on(‘click’, function() {
|
86
|
-
|
87
|
-
// flag = ‘delete’;
|
88
|
-
|
89
|
-
move(‘left_list’, ‘right_list’);
|
90
|
-
|
91
|
-
});
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
var move = function(_this, target) {
|
96
|
-
|
97
|
-
$(‘select[id=’ + _this + ‘] option:selected’).each(function() {
|
98
|
-
|
99
|
-
$(‘select[id=’ + target + ‘]’).append($(this).clone());
|
100
|
-
|
101
|
-
$(this).remove();
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
var left_list = document.getElementById('left_list');
|
106
|
-
|
107
|
-
var move_user = $(left_list).text();
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
var postData = {
|
112
|
-
|
113
|
-
'action': 'ajax_test',
|
114
|
-
|
115
|
-
'users_ID[]': move_user
|
116
|
-
|
117
|
-
};
|
118
|
-
|
119
|
-
// Ajaxで送信
|
120
|
-
|
121
|
-
$.ajax({
|
122
|
-
|
123
|
-
url: ajaxurl,
|
124
|
-
|
125
|
-
method: POST,
|
126
|
-
|
127
|
-
dataType: ‘text’,
|
128
|
-
|
129
|
-
data : postData,
|
130
|
-
|
131
|
-
}).done(function (res) {
|
132
|
-
|
133
|
-
$(‘body’).append(res);
|
134
|
-
|
135
|
-
}).fail(function (xhr, textStatus, errorThrown) {
|
136
|
-
|
137
|
-
console.log(“NG:” + xhr.status);
|
138
|
-
|
139
|
-
});
|
140
|
-
|
141
|
-
};
|
142
|
-
|
143
|
-
});。
|
144
|
-
|
145
233
|
```
|
146
234
|
|
147
235
|
```php
|
148
236
|
|
149
|
-
$button_check = $_GET;
|
150
|
-
|
151
|
-
$move_user = $_POST;
|
237
|
+
$move_user = $_POST['users_ID'][0];
|
152
|
-
|
153
|
-
|
238
|
+
|
154
|
-
|
155
|
-
move_user.forEach(function(data) {
|
156
|
-
|
157
|
-
|
239
|
+
global $wpdb;
|
240
|
+
|
158
|
-
|
241
|
+
$wpdb->delete( $wpdb->test_master ,
|
242
|
+
|
243
|
+
array(
|
244
|
+
|
245
|
+
'posts_ID' => $_SESSION['toukou_id']
|
246
|
+
|
247
|
+
) ,
|
248
|
+
|
249
|
+
array(
|
250
|
+
|
251
|
+
'%d'
|
252
|
+
|
159
|
-
|
253
|
+
));
|
254
|
+
|
255
|
+
|
256
|
+
|
160
|
-
|
257
|
+
for ($i=0; $i < count($move_user); $i++) {
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
global $wpdb;
|
262
|
+
|
263
|
+
$wpdb->insert( $wpdb->test_master ,
|
264
|
+
|
265
|
+
array(
|
266
|
+
|
267
|
+
'posts_ID' => $_SESSION['toukou_id'],
|
268
|
+
|
269
|
+
'users_ID' => $muve_user[$i]
|
270
|
+
|
271
|
+
),
|
272
|
+
|
273
|
+
array(
|
274
|
+
|
275
|
+
'%d',
|
276
|
+
|
277
|
+
'%d'
|
278
|
+
|
279
|
+
));
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
}
|
284
|
+
|
285
|
+
|
286
|
+
|
161
|
-
|
287
|
+
//if (count($move_user)!==0){
|
288
|
+
|
289
|
+
print "<script>alert('更新に成功しました。');</script>";
|
290
|
+
|
291
|
+
//}
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
|
162
296
|
|
163
297
|
```
|
3
コード修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -41,6 +41,8 @@
|
|
41
41
|
<?php
|
42
42
|
|
43
43
|
}
|
44
|
+
|
45
|
+
add_action( 'wp_head', 'add_my_ajaxurl', 1 );
|
44
46
|
|
45
47
|
|
46
48
|
|
2
コード修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -102,7 +102,7 @@
|
|
102
102
|
|
103
103
|
var left_list = document.getElementById('left_list');
|
104
104
|
|
105
|
-
var move_user = $(left_list).
|
105
|
+
var move_user = $(left_list).text();
|
106
106
|
|
107
107
|
|
108
108
|
|
@@ -144,8 +144,18 @@
|
|
144
144
|
|
145
145
|
```php
|
146
146
|
|
147
|
-
$
|
147
|
+
$button_check = $_GET;
|
148
148
|
|
149
|
+
$move_user = $_POST;
|
150
|
+
|
149
|
-
print
|
151
|
+
print("<script>
|
152
|
+
|
153
|
+
move_user.forEach(function(data) {
|
154
|
+
|
155
|
+
alert(data);
|
156
|
+
|
157
|
+
});
|
158
|
+
|
159
|
+
</script>");
|
150
160
|
|
151
161
|
```
|
1
指摘箇所の更新
test
CHANGED
File without changes
|
test
CHANGED
@@ -62,7 +62,7 @@
|
|
62
62
|
|
63
63
|
?>
|
64
64
|
|
65
|
-
|
65
|
+
```
|
66
66
|
|
67
67
|
```JavaScriputt
|
68
68
|
|
@@ -100,9 +100,17 @@
|
|
100
100
|
|
101
101
|
|
102
102
|
|
103
|
+
var left_list = document.getElementById('left_list');
|
104
|
+
|
105
|
+
var move_user = $(left_list).children();
|
106
|
+
|
107
|
+
|
108
|
+
|
103
109
|
var postData = {
|
104
110
|
|
111
|
+
'action': 'ajax_test',
|
112
|
+
|
105
|
-
move_user
|
113
|
+
'users_ID[]': move_user
|
106
114
|
|
107
115
|
};
|
108
116
|
|
@@ -112,7 +120,7 @@
|
|
112
120
|
|
113
121
|
url: ajaxurl,
|
114
122
|
|
115
|
-
method:
|
123
|
+
method: POST,
|
116
124
|
|
117
125
|
dataType: ‘text’,
|
118
126
|
|
@@ -132,10 +140,12 @@
|
|
132
140
|
|
133
141
|
});。
|
134
142
|
|
135
|
-
|
143
|
+
```
|
136
144
|
|
137
145
|
```php
|
138
146
|
|
139
147
|
$move_user = $_POST['users_ID']/*json_encode($_POST['users_ID'])*/;
|
140
148
|
|
141
149
|
print_r ($move_user);
|
150
|
+
|
151
|
+
```
|