質問編集履歴
2
不適切なコードの削除
test
CHANGED
File without changes
|
test
CHANGED
@@ -124,7 +124,7 @@
|
|
124
124
|
|
125
125
|
type: 'post',
|
126
126
|
|
127
|
-
url: "https://
|
127
|
+
url: "https://test.php",
|
128
128
|
|
129
129
|
data: {data: $("zipcode").val()},
|
130
130
|
|
1
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -83,3 +83,147 @@
|
|
83
83
|
}
|
84
84
|
|
85
85
|
```
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
追記致します
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
少し進んだのでコードを書きます
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
ajaxで$zipcodeがうまく渡らなくでアラートにNot Foundがでてしまいます。
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
```test.html
|
102
|
+
|
103
|
+
<!DOCTYPE html>
|
104
|
+
|
105
|
+
<html>
|
106
|
+
|
107
|
+
<head>
|
108
|
+
|
109
|
+
<title>郵便番号で住所入力補助</title>
|
110
|
+
|
111
|
+
<meta charset="utf-8">
|
112
|
+
|
113
|
+
<script src="../js/jquery-1.11.3.min.js"></script>
|
114
|
+
|
115
|
+
<script type="text/javascript">
|
116
|
+
|
117
|
+
$(function(){
|
118
|
+
|
119
|
+
$('#search').click(
|
120
|
+
|
121
|
+
function(){
|
122
|
+
|
123
|
+
$.ajax({
|
124
|
+
|
125
|
+
type: 'post',
|
126
|
+
|
127
|
+
url: "https://mezochita.bluebox-mp.com/verification/yubin/test.php",
|
128
|
+
|
129
|
+
data: {data: $("zipcode").val()},
|
130
|
+
|
131
|
+
success: function(data){
|
132
|
+
|
133
|
+
alert(data);
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
});
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
);
|
142
|
+
|
143
|
+
});
|
144
|
+
|
145
|
+
</script>
|
146
|
+
|
147
|
+
</head>
|
148
|
+
|
149
|
+
<body>
|
150
|
+
|
151
|
+
<form>
|
152
|
+
|
153
|
+
<p>郵便番号:<input type="text" name="zipcode" id="zip" size="8">
|
154
|
+
|
155
|
+
<input type="button" id="search" value="郵便番号で検索"></p>
|
156
|
+
|
157
|
+
<p>住所:<input size="50" type="text" name="address" id="address"></p>
|
158
|
+
|
159
|
+
</form>
|
160
|
+
|
161
|
+
</body>
|
162
|
+
|
163
|
+
</html>
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
```
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
```test.php
|
172
|
+
|
173
|
+
<?php
|
174
|
+
|
175
|
+
//郵便番号
|
176
|
+
|
177
|
+
$zipcode = $_POST['zipcode'];
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
$dir = __DIR__ . '/zipcode';
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
$zipcode = mb_convert_kana($zipcode, 'a', 'utf-8');
|
186
|
+
|
187
|
+
$zipcode = str_replace(array('-','ー'),'', $zipcode);
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
$result = array();
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
$file = $dir . DIRECTORY_SEPARATOR . substr($zipcode, 0, 1) . '.csv';
|
196
|
+
|
197
|
+
if(file_exists($file)){
|
198
|
+
|
199
|
+
$spl = new SplFileObject($file);
|
200
|
+
|
201
|
+
while (!$spl->eof()) {
|
202
|
+
|
203
|
+
$columns = $spl->fgetcsv();
|
204
|
+
|
205
|
+
if(isset($columns[0]) && $columns[0] == $zipcode){
|
206
|
+
|
207
|
+
$result = array($columns[1], $columns[2], $columns[3]);
|
208
|
+
|
209
|
+
break;
|
210
|
+
|
211
|
+
}
|
212
|
+
|
213
|
+
}
|
214
|
+
|
215
|
+
}
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
if(!empty($result)){
|
220
|
+
|
221
|
+
echo $result[0] . $result[1] . $result[2];
|
222
|
+
|
223
|
+
} else {
|
224
|
+
|
225
|
+
echo 'Not Found';
|
226
|
+
|
227
|
+
}
|
228
|
+
|
229
|
+
```
|