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

質問編集履歴

3

インデント

2018/06/27 07:59

投稿

yu-smc
yu-smc

スコア610

title CHANGED
File without changes
body CHANGED
@@ -6,30 +6,30 @@
6
6
  以下JSコードです。
7
7
  ```js
8
8
  var id = $('.messages .message:last-child').data('messageId'); //1
9
- var interval = setInterval(function(){ //2
9
+ var interval = setInterval(function(){ //2
10
- var insertHTML = '';
10
+ var insertHTML = '';
11
- if (window.location.href.match(//groups/\d+/messages/)) {
11
+ if (window.location.href.match(//groups/\d+/messages/)) {
12
- $.ajax({
12
+ $.ajax({
13
- url: location.href,
13
+ url: location.href,
14
- dataType: 'json',
14
+ dataType: 'json',
15
- })
15
+ })
16
- .done(function(data){
16
+ .done(function(data){
17
- data.forEach(function(message){ //3
17
+ data.forEach(function(message){ //3
18
- if (message.id > id) {
18
+ if (message.id > id) {
19
- console.log(id)
19
+ console.log(id)
20
- console.log(message.id)
20
+ console.log(message.id)
21
- insertHTML += buildHTML(message);
21
+ insertHTML += buildHTML(message);
22
- }
22
+ }
23
- });
23
+ });
24
- $('.messages').append(insertHTML);
24
+ $('.messages').append(insertHTML);
25
- scrollToNewest();
25
+ scrollToNewest();
26
- })
26
+ })
27
- .fail(function(data){
27
+ .fail(function(data){
28
- alert('自動更新できません。更新するにはページを再度読み込んでください。');
28
+ alert('自動更新できません。更新するにはページを再度読み込んでください。');
29
- });
29
+ });
30
- } else {
30
+ } else {
31
- clearInterval(interval);
31
+ clearInterval(interval);
32
- }
32
+ }
33
33
  id = $('.messages .message:last-child').data('messageId');
34
34
  }, 5000);
35
35
  ```

2

いんでんと

2018/06/27 07:59

投稿

yu-smc
yu-smc

スコア610

title CHANGED
File without changes
body CHANGED
@@ -4,33 +4,32 @@
4
4
  JSに慣れている方に見ていただきたく投稿しました。
5
5
 
6
6
  以下JSコードです。
7
- ```
7
+ ```js
8
- js
9
8
  var id = $('.messages .message:last-child').data('messageId'); //1
10
9
  var interval = setInterval(function(){ //2
11
- var insertHTML = '';
10
+ var insertHTML = '';
12
- if (window.location.href.match(//groups/\d+/messages/)) {
11
+ if (window.location.href.match(//groups/\d+/messages/)) {
13
- $.ajax({
12
+ $.ajax({
14
- url: location.href,
13
+ url: location.href,
15
- dataType: 'json',
14
+ dataType: 'json',
16
- })
15
+ })
17
- .done(function(data){
16
+ .done(function(data){
18
- data.forEach(function(message){ //3
17
+ data.forEach(function(message){ //3
19
- if (message.id > id) {
18
+ if (message.id > id) {
20
- console.log(id)
19
+ console.log(id)
21
- console.log(message.id)
20
+ console.log(message.id)
22
- insertHTML += buildHTML(message);
21
+ insertHTML += buildHTML(message);
23
- }
22
+ }
24
- });
23
+ });
25
- $('.messages').append(insertHTML);
24
+ $('.messages').append(insertHTML);
26
- scrollToNewest();
25
+ scrollToNewest();
27
- })
26
+ })
28
- .fail(function(data){
27
+ .fail(function(data){
29
- alert('自動更新できません。更新するにはページを再度読み込んでください。');
28
+ alert('自動更新できません。更新するにはページを再度読み込んでください。');
30
- });
29
+ });
31
- } else {
30
+ } else {
32
- clearInterval(interval);
31
+ clearInterval(interval);
33
- }
32
+ }
34
33
  id = $('.messages .message:last-child').data('messageId');
35
34
  }, 5000);
36
35
  ```

1

誤字

2018/06/27 07:52

投稿

yu-smc
yu-smc

スコア610

title CHANGED
File without changes
body CHANGED
File without changes