teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

2021/05/24 09:12

投稿

ttbdz
ttbdz

スコア2

title CHANGED
File without changes
body CHANGED
File without changes

2

誤字

2021/05/24 09:12

投稿

ttbdz
ttbdz

スコア2

title CHANGED
File without changes
body CHANGED
@@ -1,5 +1,4 @@
1
1
  ### 前提・実現したいこと
2
- 楽天ブックスのapiを使用して検索機能を作っています。
3
2
  ajaxを使用して、検索結果の総ページ数を取得し、表示させたいです。
4
3
 
5
4
  ### 発生している問題・エラーメッセージ
@@ -9,249 +8,5 @@
9
8
  ### 該当のソースコード
10
9
 
11
10
  ```jQuery
12
- <script>
13
- $(function() {
14
- var pageNum = 1;
15
- $('.search__btn').on('click', function() {
16
- $('.lists').empty();
17
- $('.pager').show();
18
- var searchWord = $('.search__text__input').val();
19
- if(searchWord === '') {
20
- $('.lists').html('<p class="message">文字が入力されていません。</p>');
21
- return false;
22
- };
23
- $.ajax({
24
- url: 'https:
25
- type: 'GET',
26
- datatype: 'json',
27
- data: {
28
- keyword: searchWord,
29
- applicationId: '',
30
- booksGenreId: '001'
31
- page: 1,
32
- hits: 20,
33
- pageCount: searchWord,
34
- }
35
- }).done(function(data) {
36
- if(data.hits === 0) {
37
- $('.lists').html('<p class="message">検索結果がありませんでした。別のキーワードで検索してください</p>');
38
- }
39
- $.each(data.Items,function(index,element) {
40
- var book = '<li class="lists__item">' +
41
- '<div class="lists__item__inner">' +
42
- '<a href="'+ element.Item.itemUrl +'"class="lists__item__link" target="_blank">' +
43
- '<img src="'+ element.Item.mediumImageUrl +'" class="lists__item__img" alt="">' +
44
- '<p class="lists__item__detail">作品名:'+ element.Item.title +'</p>' +
45
- '<p class="lists__item__detail">作者:'+ element.Item.author +'</p>' +
46
- '<p class="lists__item__detail">出版社:'+ element.Item.publisherName +'</p>' +
47
- '</a>' +
48
- '</div>' +
49
- '</li>';
50
- $('.lists').append(book);
51
- $('.counter').html('<span class="counter-current">'+ pageNum +'</span>/<span class="counter-all">'+ element.Item.pageCount +'</span>')//この行のelement.Item.pageCountがundefinedになってしまう。
11
+ $('.counter').html('<span class="counter-current">'+ pageNum +'</span>/<span class="counter-all">'+ element.Item.pageCount +'</span>')
52
-
53
- })
54
- console.log(element.Item)
55
- }).fail(function(data) {
56
- $('.lists').html('<p class="message">データ通信ができませんでした。接続を確認してください。</p>');
57
- });
58
- });
59
- });
60
- </script>
61
- ```
62
- ### 補足情報(FW/ツールのバージョンなど)
63
- ```html
64
- <!doctype html>
65
- <html>
66
- <head>
67
- <meta charset="UTF-8">
68
- <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
69
- <meta name="format-detection" content="telephone=no">
70
- <title>jQuery</title>
71
- <link rel="stylesheet" href="../../common/css/reset.css">
72
- <link rel="stylesheet" href="../../common/css/base.css">
73
- <link rel="stylesheet" href="./css/style.css">
74
- </head>
75
- <body>
76
- <div class="wrap">
77
- <div class="container">
78
- <div class="header">
79
- <p class="header__title">Search Books!</p>
80
- </div>
81
- <div class="search">
82
- <div class="search__text">
83
- <input type="text" class="search__text__input" placeholder="検索する" data-js="search-word">
84
- </div>
85
- <button class="search__btn" data-js="search-btn">検索する</button>
86
- </div>
87
- <div class="message"></div>
88
- <ul class="lists"></ul>
89
- <div class="pager" data-js="pager">
90
- <div class="counter">
91
- <span class="counter-current"></span>/<span class="counter-all"></span>
92
- </div>
93
- <div class="btn-wrapper">
94
- <a class="btn-item" data-js="page-prev" href="">前へ</a>
95
- <a class="btn-item" data-js="page-next" href="">次へ</a>
96
- </div>
97
- </div>
98
- </div>
99
- </div>
100
- <script src="../../common/js/jquery.js"></script>
101
- <script src="./js/appid.js"></script>
102
- ```
103
- ```css
104
- .clearfix::after {
105
- display: block;
106
- clear: both;
107
- content: '';
108
- }
109
- .wrap {
110
- padding-bottom: 40px;
111
- }
112
- .header {
113
- width: 100%;
114
- background-color: #43cee0;
115
- }
116
- .header__title {
117
- line-height: 60px;
118
- text-align: center;
119
- font-size: 20px;
120
- color: #fff;
121
- }
122
- .search {
123
- overflow: hidden;
124
- margin-bottom: 50px;
125
- background: #fff;
126
- box-shadow: 0 1px 5px #ccc;
127
- }
128
- .search__text {
129
- width: 100%;
130
- }
131
- .search__text__input {
132
- -webkit-box-sizing: border-box;
133
- box-sizing: border-box;
134
- width: 100%;
135
- margin-bottom: 20px;
136
- padding: 0 10px;
137
- line-height: 3em;
138
- border-top: none;
139
- border-left: none;
140
- border-right: none;
141
- border-bottom: 1px solid #eee;
142
- font-size: 20px;
143
- }
144
- .search__btn {
145
- display: block;
146
- margin: 0 auto 20px;
147
- padding: 0 20px;
148
- line-height: 40px;
149
- border: none;
150
- font-size: 18px;
151
- color: #fff;
152
- background-color: #43cee0;
153
- cursor: pointer;
154
- }
155
- .search__btn:hover {
156
- background-color: #1eabbd;
157
- }
158
- .lists {
159
- overflow: hidden;
160
- margin-left: 20px;
161
-
162
- }
163
- .lists__item {
164
- -webkit-box-sizing: border-box;
165
- box-sizing: border-box;
166
- display: inline-block;
167
- width: 25%;
168
- padding: 0 20px 20px 0;
169
- vertical-align: top;
170
- text-align: center;
171
- }
172
- .lists__item__inner {
173
- width: 100%;
174
- max-width: 200px;
175
- margin: 0 auto;
176
- }
177
- .lists__item__link {
178
- display: block;
179
- text-decoration: none;
180
- }
181
- .lists__item__img {
182
- margin-bottom: 20px;
183
- width: 100%;
184
- max-width: 150px;
185
- -webkit-box-shadow: 0 1px 5px #ccc;
186
- box-shadow: 0 1px 5px #ccc;
187
- }
188
- .lists__item__detail {
189
- margin-bottom: 10px;
190
- padding-left: 5em;
191
- text-indent: -5em;
192
- line-height: 1.5em;
193
- text-align: left;
194
- font-size: 12px;
195
- }
196
- .message {
197
- margin-bottom: 50px;
198
- text-align: center;
199
- }
200
- .pager {
201
- border-top: 1px solid #ccc;
202
- padding-top: 35px;
203
- }
204
- .btn-wrapper {
205
- display: flex;
206
- justify-content: center;
207
- margin-top: 20px;
208
- }
209
- .btn-item {
210
- width: 80px;
211
- height: 40px;
212
- line-height: 40px;
213
- box-sizing: border-box;
214
- background-color: #43cee0;
215
- color: #fff;
216
- margin-left: 10px;
217
- display: block;
218
- font-size: 16px;
219
- text-align: center;
220
- }
221
- .btn-item:hover:not(.disabled) {
222
- background-color: #1eabbd;
223
- }
224
- .btn-item:first-child {
225
- margin-left: 0;
226
- }
227
- .disabled {
228
- background-color: #888;
229
- }
230
- .disabled.btn-item {
231
- cursor: default;
232
- }
233
- .counter {
234
- text-align: center;
235
- font-size: 20px;
236
- font-weight: bold;
237
- }
238
- .counter-current {
239
- margin-right: 10px;
240
- color: #43cee0;
241
- }
242
- .counter-all {
243
- margin-left: 10px;
244
- }
245
-
246
- @media screen and (max-width: 767px) {
247
- .lists__item {
248
- width: 33.33%;
249
- }
250
- }
251
-
252
- @media screen and (max-width: 479px) {
253
- .lists__item {
254
- width: 50%;
255
- }
256
- }
257
12
  ```

1

2021/05/23 22:24

投稿

ttbdz
ttbdz

スコア2

title CHANGED
File without changes
body CHANGED
@@ -3,7 +3,7 @@
3
3
  ajaxを使用して、検索結果の総ページ数を取得し、表示させたいです。
4
4
 
5
5
  ### 発生している問題・エラーメッセージ
6
- element.Item.pageCountと書いたところで総ページ数を取得するつもりがundefinedになってしまう。
6
+ element.Item.pageCountと書いたところで総ページ数を取得するつもりがundefinedになってしまうのでこれを直したいです
7
7
 
8
8
 
9
9
  ### 該当のソースコード