質問編集履歴
1
該当ソースコードの追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -32,4 +32,84 @@
|
|
32
32
|
|
33
33
|
皆様の知識でお教えいただければと思います。
|
34
34
|
|
35
|
-
宜しくお願いいたします。
|
35
|
+
宜しくお願いいたします。
|
36
|
+
|
37
|
+
##追記
|
38
|
+
ご指摘をいただきましたので、該当のJavaScriptファイルのソースコードを記載します。
|
39
|
+
宜しくお願いいたします。
|
40
|
+
|
41
|
+
```js
|
42
|
+
'use strict';
|
43
|
+
|
44
|
+
const w = window,
|
45
|
+
d = document
|
46
|
+
;
|
47
|
+
|
48
|
+
const $ = id => {
|
49
|
+
return d.getElementById(id);
|
50
|
+
}
|
51
|
+
|
52
|
+
const $t = tag => {
|
53
|
+
return d.getElementsByTagName(tag);
|
54
|
+
}
|
55
|
+
|
56
|
+
const $c = cls => {
|
57
|
+
return d.getElementsByClassName(cls);
|
58
|
+
}
|
59
|
+
|
60
|
+
class User{
|
61
|
+
|
62
|
+
constructor(){
|
63
|
+
const form = $t('form');
|
64
|
+
this.xhr = new XMLHttpRequest();
|
65
|
+
|
66
|
+
for(let i=0; i < form.length; i++){
|
67
|
+
form[i].addEventListener('submit', (e) => {
|
68
|
+
return e.preventDefault();
|
69
|
+
});
|
70
|
+
}
|
71
|
+
|
72
|
+
$('tweet_btn').addEventListener('click', () => {
|
73
|
+
this.postTweet();
|
74
|
+
this.getNewTweets();
|
75
|
+
});
|
76
|
+
|
77
|
+
this.xhr.onreadystatechange = () => {
|
78
|
+
if (this.xhr.readyState === 4 && this.xhr.status === 200){
|
79
|
+
}
|
80
|
+
}
|
81
|
+
}
|
82
|
+
|
83
|
+
postTweet() {
|
84
|
+
const url = './tweet.php',
|
85
|
+
tweet_msg = $('tweet_msg').value,
|
86
|
+
data = {
|
87
|
+
tweet : tweet_msg,
|
88
|
+
mode : 'ALL'
|
89
|
+
}
|
90
|
+
;
|
91
|
+
|
92
|
+
this.xhr.open('POST', url);
|
93
|
+
this.xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
|
94
|
+
this.xhr.send(JSON.stringify(data));
|
95
|
+
}
|
96
|
+
|
97
|
+
getNewTweets() {
|
98
|
+
const url = './tweet.php',
|
99
|
+
latest = $c('tweet_date').item(0).innerText,
|
100
|
+
data = {
|
101
|
+
latest : latest,
|
102
|
+
mode : 'LATEST'
|
103
|
+
}
|
104
|
+
;
|
105
|
+
|
106
|
+
this.xhr.open('POST', url);
|
107
|
+
this.xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
|
108
|
+
this.xhr.send(JSON.stringify(data));
|
109
|
+
console.log(this.xhr.responseText);
|
110
|
+
}
|
111
|
+
|
112
|
+
}
|
113
|
+
|
114
|
+
const user = new User();
|
115
|
+
```
|