File tree 1 file changed +9
-9
lines changed 1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change 1
- document . addEventListener ( "DOMContentLoaded" , function ( ) {
1
+
2
+ const answerUrl = baseUrl + 'questions/answers' ;
3
+
4
+ document . addEventListener ( "DOMContentLoaded" , function ( ) {
2
5
3
6
fetch ( baseUrl + 'questions/recent' ) . then ( response => {
4
7
return response . json ( ) ;
@@ -46,20 +49,17 @@ function saveAnswer(questionId) {
46
49
questionId = findDom ( 'featured-question-id' ) . value ;
47
50
const userId = findDom ( 'featured-question-user-id' ) . value ;
48
51
const answer = findDom ( 'answer-body' ) . value ;
49
- const answerUrl = baseUrl + 'questions/answers' ;
50
52
const queryBody = 'question_id=' + questionId + '&user_id=' + userId + '&answer=' + answer ;
51
53
//check if valid characters are entered in answer text
52
54
if ( typeof answer === "string" && answer . trim ( ) . length >= 5 ) {
53
55
fetch ( answerUrl ,
54
56
{
55
57
method : 'post' ,
56
58
headers : {
57
- "Content-type" : "application/x-www-form-urlencoded; charset=UTF-8" ,
58
- "authorization" : localStorage . Authorization
59
+ "Content-type" : "application/x-www-form-urlencoded; charset=UTF-8" , "authorization" : localStorage . Authorization
59
60
} ,
60
61
body : queryBody
61
- } )
62
- . then ( response => {
62
+ } ) . then ( response => {
63
63
return response . json ( ) ;
64
64
} ) . then ( data => {
65
65
if ( data [ 'status' ] === 200 ) {
@@ -69,12 +69,12 @@ fetch(answerUrl,
69
69
}
70
70
} ) . catch ( err => {
71
71
console . log ( err ) ;
72
- // Do something for an error here
73
72
} ) ;
74
73
} else {
75
74
showAnswerSaveError ( ) ;
76
- }
77
- }
75
+ } }
76
+
77
+
78
78
79
79
80
80
function showAnswerForm ( ) {
You can’t perform that action at this time.
0 commit comments