/**
 * Created by wangbo on 2017/4/13.
 */

import React, {Component} from 'react'

import 'es6-promise'
import 'isomorphic-fetch'


class FetchTest extends Component {
  constructor(props) {
    super(props);

    this.state = {url: "www.baidu.com"};

    this.handleClick = this.handleClick.bind(this);
    this.handleInput = this.handleInput.bind(this);
  }

  handleInput(e) {
    console.log("change url " + e.target.value);
    this.setState({url: e.target.value});
  }

  handleClick(e) {
    e.preventDefault();
    console.log("fetch url : " + this.state.url)
    fetch(this.state.url)
      .then((response) => {
        console.log("fetch result :" + response.status)
      }).catch((e) => {
      console.log(" fetch error ")
    })
  }

  render() {
    return (
      <div>
        <input type="text" onChange={this.handleInput} value={this.state.url}/>
        <button onClick={this.handleClick}>Fetch</button>
      </div>
    )
  }
}

export default FetchTest
@@ -226,28 +226,149 @@
  = %7B
-url: %22www.baidu.com%22
+%0A      url: %22int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip=218.4.255.12%22,%0A      fetchResult: %22waiting%22,%0A      fetchData: %22%22%0A    
 %7D;%0A%0A
@@ -679,24 +679,467 @@
 .state.url)%0A
+    this.setState(%7BfetchResult: %22waiting%22%7D);%0A%0A    var init = %7B%0A        method: 'GET',%0A        mode: 'cors',%0A        cache: 'default',%0A        headers: %7B%0A          // 'Access-Control-Allow-Origin': %22*%22,%0A          // 'Accept': 'application/x-www-form-urlencoded',%0A          // 'Access-Control-Allow-Methods': 'POST, GET, OPTIONS, PUT, DELETE',%0A          // 'Authorization':'Bearer e3a4ca4b-bdaa-4034-a842-3641055819a3'%0A        %7D%0A      %7D%0A    ;%0A%0A%0A
     fetch(th
@@ -1146,24 +1146,30 @@
 is.state.url
+, init
 )%0A      .the
@@ -1240,24 +1240,244 @@
 e.status
+ + %22_%22 + response.ok)%0A        this.setState(%7BfetchResult: %22success %22 + response.status + %22_%22 + response.ok%7D);%0A        return response.text()%0A      %7D)%0A      .then(data =%3E %7B%0A        this.setState(%7BfetchData: data%7D)%0A      %7D
 )%0A      
 %7D).catch
@@ -1468,18 +1468,16 @@
 )%0A      
-%7D)
 .catch((
@@ -1480,24 +1480,26 @@
 ch((e) =%3E %7B%0A
+  
       consol
@@ -1521,16 +1521,68 @@
 rror %22)%0A
+        this.setState(%7BfetchResult: %22error%22 + e%7D)%0A  
     %7D)%0A 
@@ -1761,16 +1761,121 @@
 button%3E%0A
+        %3Cp%3EFetch result : %7Bthis.state.fetchResult%7D%3C/p%3E%0A        %3Cp%3EFetch Data: %7Bthis.state.fetchData%7D%3C/p%3E%0A
       %3C/

add fetch init obj