-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.html
More file actions
65 lines (60 loc) · 2.04 KB
/
api.html
File metadata and controls
65 lines (60 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://unpkg.com/react@18/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js" crossorigin></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
class CityForm extends React.Component {
constructor(props) {
super(props);
this.state = {value: '', cities:[{"city":"Provo"},{"city":"Lindon"}]};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event) {
alert('A name was changed: ' + event.target.value);
this.setState({value: event.target.value});
var url = "https://csonline.fhtl.org?q=" + event.target.value;
console.log("URL " + url);
fetch(url)
.then((data) => {
return (data.json());
})
.then((citylist) => {
console.log("CityList");
console.log(citylist);
this.setState({cities:citylist})
console.log(this.state.cities);
});
}
handleSubmit(event) {
alert('A name was submitted: ' + this.state.value);
event.preventDefault();
}
render() {
const listItems = this.state.cities.map((cityname) =>
<li key={cityname.city}>{cityname.city}</li>
);
return (
<div>
<form onSubmit={this.handleSubmit} onKeyUp={this.handleChange}>
<label>
Name:
<input type="text" value={this.state.value} onChange={this.handleChange} />
</label>
<input type="submit" value="Submit" />
</form>
<ul>{listItems}</ul>
</div>
);
}
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<CityForm />);
</script>
</body>
</html>