回答編集履歴

1

動作確認内容を追記

2018/03/10 02:16

投稿

nakazawaken1
nakazawaken1

スコア94

test CHANGED
@@ -5,3 +5,159 @@
5
5
  var post_data = {'com' : name};
6
6
 
7
7
  ではないでしょうか。
8
+
9
+
10
+
11
+ ■追記■
12
+
13
+ 次のファイルで動作確認してみましたが正常にPOSTされているようです。
14
+
15
+ [post.php]
16
+
17
+ ```php
18
+
19
+ <?php
20
+
21
+ #入力内容をファイルに記録
22
+
23
+ error_log(date(DATE_ATOM) . ' ' . $_REQUEST['com'] . "\r\n", 3, '/tmp/post.php.log');
24
+
25
+ ?>ok
26
+
27
+ ```
28
+
29
+
30
+
31
+ [post.html]
32
+
33
+ ```html
34
+
35
+ <html>
36
+
37
+ <head>
38
+
39
+ <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.js"></script>
40
+
41
+ <script type="text/javascript">
42
+
43
+ jQuery(function($) {
44
+
45
+ $('#send').submit(function(){
46
+
47
+ var name = $('#com').val();
48
+
49
+ if (name.length === 0){
50
+
51
+ return false;
52
+
53
+ } else {
54
+
55
+ var post_data = {'com' : name};
56
+
57
+ $.ajax({
58
+
59
+ type: 'POST',
60
+
61
+ url: 'post.php',
62
+
63
+ data: post_data,
64
+
65
+ });
66
+
67
+ return false;
68
+
69
+ };
70
+
71
+ });
72
+
73
+ });
74
+
75
+ </script>
76
+
77
+ </head>
78
+
79
+ <body>
80
+
81
+ <form id="send">
82
+
83
+ <input name="com" type="text" id="com" class="text" maxlength="30"/>
84
+
85
+ <input type="submit" class="submit" value="投稿"/>
86
+
87
+ </form>
88
+
89
+ </body>
90
+
91
+ </html>
92
+
93
+ ```
94
+
95
+
96
+
97
+ [post.htmlを開いて入力]
98
+
99
+ ![入力](2f9359b151c60f423277df81b293b395.jpeg)
100
+
101
+
102
+
103
+ [/tmp/post.php.log]
104
+
105
+ ```
106
+
107
+ 2018-03-10T00:34:28+00:00 aaa
108
+
109
+
110
+
111
+ ```
112
+
113
+
114
+
115
+ どうしてもだめそうなら以下のコードで試してみてください。
116
+
117
+ [post.html修正版]
118
+
119
+ ```html
120
+
121
+ <html>
122
+
123
+ <head>
124
+
125
+ <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.js"></script>
126
+
127
+ <script type="text/javascript">
128
+
129
+ jQuery(function($) {
130
+
131
+ $('#send').on('click', function(){
132
+
133
+ var name = $('#com').val();
134
+
135
+ if (name.length > 0){
136
+
137
+ $.post('post.php', {com : name});
138
+
139
+ };
140
+
141
+ });
142
+
143
+ });
144
+
145
+ </script>
146
+
147
+ </head>
148
+
149
+ <body>
150
+
151
+ <form>
152
+
153
+ <input type="text" id="com" class="text" maxlength="30"/>
154
+
155
+ <input type="button" id="send" class="submit" value="投稿"/>
156
+
157
+ </form>
158
+
159
+ </body>
160
+
161
+ </html>
162
+
163
+ ```