aminskjen commited on
Commit
21aecb6
·
verified ·
1 Parent(s): 97f75ca

Update static/js/script.js

Browse files
Files changed (1) hide show
  1. static/js/script.js +19 -9
static/js/script.js CHANGED
@@ -45,15 +45,25 @@ class InkBoard {
45
  this.setButtonLoading(true);
46
 
47
  const response = await fetch('/generate', {
48
- method: 'POST',
49
- headers: {
50
- 'Content-Type': 'application/json',
51
- },
52
- body: JSON.stringify({
53
- scene_idea: sceneIdea
54
- })
55
- });
56
-
 
 
 
 
 
 
 
 
 
 
57
  const data = await response.json();
58
 
59
  if (data.success) {
 
45
  this.setButtonLoading(true);
46
 
47
  const response = await fetch('/generate', {
48
+ method: 'POST',
49
+ headers: { 'Content-Type': 'application/json' },
50
+ body: JSON.stringify({ scene_idea: userInput })
51
+ })
52
+ .then(res => {
53
+ if (!res.ok) throw new Error("Server error");
54
+ return res.json();
55
+ })
56
+ .then(data => {
57
+ if (data.error) throw new Error(data.error);
58
+ displayStory(data.story);
59
+ displayImage(data.image_url);
60
+ })
61
+ .catch(err => {
62
+ console.error("Fetch error:", err.message);
63
+ alert("Oops! " + err.message);
64
+ });
65
+
66
+
67
  const data = await response.json();
68
 
69
  if (data.success) {