質問編集履歴

3

2021/05/24 09:12

投稿

ttbdz
ttbdz

スコア2

test CHANGED
File without changes
test CHANGED
File without changes

2

誤字

2021/05/24 09:12

投稿

ttbdz
ttbdz

スコア2

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,4 @@
1
1
  ### 前提・実現したいこと
2
-
3
- 楽天ブックスのapiを使用して検索機能を作っています。
4
2
 
5
3
  ajaxを使用して、検索結果の総ページ数を取得し、表示させたいです。
6
4
 
@@ -20,494 +18,6 @@
20
18
 
21
19
  ```jQuery
22
20
 
23
- <script>
24
-
25
- $(function() {
26
-
27
- var pageNum = 1;
28
-
29
- $('.search__btn').on('click', function() {
30
-
31
- $('.lists').empty();
32
-
33
- $('.pager').show();
34
-
35
- var searchWord = $('.search__text__input').val();
36
-
37
- if(searchWord === '') {
38
-
39
- $('.lists').html('<p class="message">文字が入力されていません。</p>');
40
-
41
- return false;
42
-
43
- };
44
-
45
- $.ajax({
46
-
47
- url: 'https:
48
-
49
- type: 'GET',
50
-
51
- datatype: 'json',
52
-
53
- data: {
54
-
55
- keyword: searchWord,
56
-
57
- applicationId: '',
58
-
59
- booksGenreId: '001'
60
-
61
- page: 1,
62
-
63
- hits: 20,
64
-
65
- pageCount: searchWord,
66
-
67
- }
68
-
69
- }).done(function(data) {
70
-
71
- if(data.hits === 0) {
72
-
73
- $('.lists').html('<p class="message">検索結果がありませんでした。別のキーワードで検索してください</p>');
74
-
75
- }
76
-
77
- $.each(data.Items,function(index,element) {
78
-
79
- var book = '<li class="lists__item">' +
80
-
81
- '<div class="lists__item__inner">' +
82
-
83
- '<a href="'+ element.Item.itemUrl +'"class="lists__item__link" target="_blank">' +
84
-
85
- '<img src="'+ element.Item.mediumImageUrl +'" class="lists__item__img" alt="">' +
86
-
87
- '<p class="lists__item__detail">作品名:'+ element.Item.title +'</p>' +
88
-
89
- '<p class="lists__item__detail">作者:'+ element.Item.author +'</p>' +
90
-
91
- '<p class="lists__item__detail">出版社:'+ element.Item.publisherName +'</p>' +
92
-
93
- '</a>' +
94
-
95
- '</div>' +
96
-
97
- '</li>';
98
-
99
- $('.lists').append(book);
100
-
101
- $('.counter').html('<span class="counter-current">'+ pageNum +'</span>/<span class="counter-all">'+ element.Item.pageCount +'</span>')//この行のelement.Item.pageCountがundefinedになってしまう。
21
+ $('.counter').html('<span class="counter-current">'+ pageNum +'</span>/<span class="counter-all">'+ element.Item.pageCount +'</span>')
102
-
103
-
104
-
105
- })
106
-
107
- console.log(element.Item)
108
-
109
- }).fail(function(data) {
110
-
111
- $('.lists').html('<p class="message">データ通信ができませんでした。接続を確認してください。</p>');
112
-
113
- });
114
-
115
- });
116
-
117
- });
118
-
119
- </script>
120
22
 
121
23
  ```
122
-
123
- ### 補足情報(FW/ツールのバージョンなど)
124
-
125
- ```html
126
-
127
- <!doctype html>
128
-
129
- <html>
130
-
131
- <head>
132
-
133
- <meta charset="UTF-8">
134
-
135
- <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
136
-
137
- <meta name="format-detection" content="telephone=no">
138
-
139
- <title>jQuery</title>
140
-
141
- <link rel="stylesheet" href="../../common/css/reset.css">
142
-
143
- <link rel="stylesheet" href="../../common/css/base.css">
144
-
145
- <link rel="stylesheet" href="./css/style.css">
146
-
147
- </head>
148
-
149
- <body>
150
-
151
- <div class="wrap">
152
-
153
- <div class="container">
154
-
155
- <div class="header">
156
-
157
- <p class="header__title">Search Books!</p>
158
-
159
- </div>
160
-
161
- <div class="search">
162
-
163
- <div class="search__text">
164
-
165
- <input type="text" class="search__text__input" placeholder="検索する" data-js="search-word">
166
-
167
- </div>
168
-
169
- <button class="search__btn" data-js="search-btn">検索する</button>
170
-
171
- </div>
172
-
173
- <div class="message"></div>
174
-
175
- <ul class="lists"></ul>
176
-
177
- <div class="pager" data-js="pager">
178
-
179
- <div class="counter">
180
-
181
- <span class="counter-current"></span>/<span class="counter-all"></span>
182
-
183
- </div>
184
-
185
- <div class="btn-wrapper">
186
-
187
- <a class="btn-item" data-js="page-prev" href="">前へ</a>
188
-
189
- <a class="btn-item" data-js="page-next" href="">次へ</a>
190
-
191
- </div>
192
-
193
- </div>
194
-
195
- </div>
196
-
197
- </div>
198
-
199
- <script src="../../common/js/jquery.js"></script>
200
-
201
- <script src="./js/appid.js"></script>
202
-
203
- ```
204
-
205
- ```css
206
-
207
- .clearfix::after {
208
-
209
- display: block;
210
-
211
- clear: both;
212
-
213
- content: '';
214
-
215
- }
216
-
217
- .wrap {
218
-
219
- padding-bottom: 40px;
220
-
221
- }
222
-
223
- .header {
224
-
225
- width: 100%;
226
-
227
- background-color: #43cee0;
228
-
229
- }
230
-
231
- .header__title {
232
-
233
- line-height: 60px;
234
-
235
- text-align: center;
236
-
237
- font-size: 20px;
238
-
239
- color: #fff;
240
-
241
- }
242
-
243
- .search {
244
-
245
- overflow: hidden;
246
-
247
- margin-bottom: 50px;
248
-
249
- background: #fff;
250
-
251
- box-shadow: 0 1px 5px #ccc;
252
-
253
- }
254
-
255
- .search__text {
256
-
257
- width: 100%;
258
-
259
- }
260
-
261
- .search__text__input {
262
-
263
- -webkit-box-sizing: border-box;
264
-
265
- box-sizing: border-box;
266
-
267
- width: 100%;
268
-
269
- margin-bottom: 20px;
270
-
271
- padding: 0 10px;
272
-
273
- line-height: 3em;
274
-
275
- border-top: none;
276
-
277
- border-left: none;
278
-
279
- border-right: none;
280
-
281
- border-bottom: 1px solid #eee;
282
-
283
- font-size: 20px;
284
-
285
- }
286
-
287
- .search__btn {
288
-
289
- display: block;
290
-
291
- margin: 0 auto 20px;
292
-
293
- padding: 0 20px;
294
-
295
- line-height: 40px;
296
-
297
- border: none;
298
-
299
- font-size: 18px;
300
-
301
- color: #fff;
302
-
303
- background-color: #43cee0;
304
-
305
- cursor: pointer;
306
-
307
- }
308
-
309
- .search__btn:hover {
310
-
311
- background-color: #1eabbd;
312
-
313
- }
314
-
315
- .lists {
316
-
317
- overflow: hidden;
318
-
319
- margin-left: 20px;
320
-
321
-
322
-
323
- }
324
-
325
- .lists__item {
326
-
327
- -webkit-box-sizing: border-box;
328
-
329
- box-sizing: border-box;
330
-
331
- display: inline-block;
332
-
333
- width: 25%;
334
-
335
- padding: 0 20px 20px 0;
336
-
337
- vertical-align: top;
338
-
339
- text-align: center;
340
-
341
- }
342
-
343
- .lists__item__inner {
344
-
345
- width: 100%;
346
-
347
- max-width: 200px;
348
-
349
- margin: 0 auto;
350
-
351
- }
352
-
353
- .lists__item__link {
354
-
355
- display: block;
356
-
357
- text-decoration: none;
358
-
359
- }
360
-
361
- .lists__item__img {
362
-
363
- margin-bottom: 20px;
364
-
365
- width: 100%;
366
-
367
- max-width: 150px;
368
-
369
- -webkit-box-shadow: 0 1px 5px #ccc;
370
-
371
- box-shadow: 0 1px 5px #ccc;
372
-
373
- }
374
-
375
- .lists__item__detail {
376
-
377
- margin-bottom: 10px;
378
-
379
- padding-left: 5em;
380
-
381
- text-indent: -5em;
382
-
383
- line-height: 1.5em;
384
-
385
- text-align: left;
386
-
387
- font-size: 12px;
388
-
389
- }
390
-
391
- .message {
392
-
393
- margin-bottom: 50px;
394
-
395
- text-align: center;
396
-
397
- }
398
-
399
- .pager {
400
-
401
- border-top: 1px solid #ccc;
402
-
403
- padding-top: 35px;
404
-
405
- }
406
-
407
- .btn-wrapper {
408
-
409
- display: flex;
410
-
411
- justify-content: center;
412
-
413
- margin-top: 20px;
414
-
415
- }
416
-
417
- .btn-item {
418
-
419
- width: 80px;
420
-
421
- height: 40px;
422
-
423
- line-height: 40px;
424
-
425
- box-sizing: border-box;
426
-
427
- background-color: #43cee0;
428
-
429
- color: #fff;
430
-
431
- margin-left: 10px;
432
-
433
- display: block;
434
-
435
- font-size: 16px;
436
-
437
- text-align: center;
438
-
439
- }
440
-
441
- .btn-item:hover:not(.disabled) {
442
-
443
- background-color: #1eabbd;
444
-
445
- }
446
-
447
- .btn-item:first-child {
448
-
449
- margin-left: 0;
450
-
451
- }
452
-
453
- .disabled {
454
-
455
- background-color: #888;
456
-
457
- }
458
-
459
- .disabled.btn-item {
460
-
461
- cursor: default;
462
-
463
- }
464
-
465
- .counter {
466
-
467
- text-align: center;
468
-
469
- font-size: 20px;
470
-
471
- font-weight: bold;
472
-
473
- }
474
-
475
- .counter-current {
476
-
477
- margin-right: 10px;
478
-
479
- color: #43cee0;
480
-
481
- }
482
-
483
- .counter-all {
484
-
485
- margin-left: 10px;
486
-
487
- }
488
-
489
-
490
-
491
- @media screen and (max-width: 767px) {
492
-
493
- .lists__item {
494
-
495
- width: 33.33%;
496
-
497
- }
498
-
499
- }
500
-
501
-
502
-
503
- @media screen and (max-width: 479px) {
504
-
505
- .lists__item {
506
-
507
- width: 50%;
508
-
509
- }
510
-
511
- }
512
-
513
- ```

1

2021/05/23 22:24

投稿

ttbdz
ttbdz

スコア2

test CHANGED
File without changes
test CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  ### 発生している問題・エラーメッセージ
10
10
 
11
- element.Item.pageCountと書いたところで総ページ数を取得するつもりがundefinedになってしまう。
11
+ element.Item.pageCountと書いたところで総ページ数を取得するつもりがundefinedになってしまうのでこれを直したいです
12
12
 
13
13
 
14
14