Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 5c3a3ee

Browse files
committed
Try fetch instead of jquery
1 parent 3905e5b commit 5c3a3ee

2 files changed

Lines changed: 21 additions & 28 deletions

File tree

runestone/common/js/runestonebase.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,16 @@ export default class RunestoneBase {
6969
eventInfo.percent = this.percent;
7070
}
7171
if (eBookConfig.useRunestoneServices && eBookConfig.logLevel > 0) {
72-
post_return = jQuery.post(
73-
eBookConfig.ajaxURL + "hsblog",
74-
eventInfo,
75-
function (jsondata) {
76-
if (jsondata.log == false) {
77-
alert(jsondata.message);
78-
location.href =
79-
eBookConfig.app +
80-
"/default/user/login?_next=" +
81-
location.pathname;
82-
}
83-
},
84-
"json"
85-
);
72+
let headers = new Headers({
73+
"Content-type": "application/json; charset=utf-8",
74+
Accept: "application/json",
75+
});
76+
let request = new Request(eBookConfig.ajaxURL + "hsblog", {
77+
method: "POST",
78+
headers: headers,
79+
body: JSON.stringify(eventInfo),
80+
});
81+
post_return = fetch(request);
8682
}
8783
console.log("logging event " + JSON.stringify(eventInfo));
8884
if (

runestone/fitb/js/fitb.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,13 @@ export default class FITB extends RunestoneBase {
205205
}
206206
}
207207

208-
logCurrentAnswer() {
208+
async logCurrentAnswer() {
209209
let answer = JSON.stringify(this.given_arr);
210210
// Save the answer locally.
211211
this.setLocalStorage({
212212
answer: answer,
213213
timestamp: new Date(),
214214
});
215-
var that = this;
216215
var ret = this.logBookEvent({
217216
event: "fillb",
218217
act: answer,
@@ -235,27 +234,25 @@ export default class FITB extends RunestoneBase {
235234
* renderFeedback()
236235
* independently.
237236
*/
238-
startEvaluation(logFlag) {
237+
async startEvaluation(logFlag) {
239238
this.checkCurrentAnswer();
240239
if (this.feedbackArray) {
241240
this.renderFeedback();
242241
}
243242
if (logFlag) {
244243
// Sometimes we don't want to log the answer--for example, when timed exam questions are re-loaded
245-
let ret = this.logCurrentAnswer();
244+
let ret = await this.logCurrentAnswer();
246245
if (!this.feedbackArray) {
247246
// On success, update the feedback from the server's grade.
248-
let that = this;
249-
ret.done(function (data) {
250-
that.setLocalStorage({
251-
answer: answer,
252-
timestamp: data.timestamp,
253-
});
254-
that.correct = data.correct;
255-
that.displayFeed = data.displayFeed;
256-
that.isCorrectArray = data.isCorrectArray;
257-
that.renderFeedback();
247+
let data = await ret.json();
248+
this.setLocalStorage({
249+
answer: JSON.stringify(this.given_arr),
250+
timestamp: data.timestamp,
258251
});
252+
this.correct = data.correct;
253+
this.displayFeed = data.displayFeed;
254+
this.isCorrectArray = data.isCorrectArray;
255+
this.renderFeedback();
259256
}
260257
}
261258
if (this.useRunestoneServices) {

0 commit comments

Comments
 (0)