3.21. React AJAX

发布时间 :2024-03-14 23:00:04 UTC      

Data from the React component can be accessed through the componentDidMount method, and when getting data from the server, it can be stored in the state , reuse this.setState method to re-renderUI.

When loading data asynchronously, use the componentWillUnmount to cancel the outstanding request.

The following example demonstrates getting the latest Github user updates gist share description:

3.21.1. React instance

classUserGistextendsReact.Component{constructor(props){super(props);this.state={username:'',lastGistUrl:''};}componentDidMount(){this.serverRequest=
$.get(this.props.source,function(result){varlastGist=result[0];this.setState({username:lastGist.owner.login,lastGistUrl:lastGist.html_url});}.bind(this));}componentWillUnmount(){this.serverRequest.abort();}render(){return(<div>{this.state.username}User's latest Gist shared address:
<ahref={this.state.lastGistUrl}>{this.state.lastGistUrl}</a>
</div>);}}ReactDOM.render(<UserGistsource="https://api.github.com/users/octocat/gists"/>,document.getElementById('example'));

The above code uses jQuery to complete the Ajax request.

Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.