2017-09-23 207 views
0
import React, {Component} from 'react'; 
import ReactDOM from 'react-dom'; 
import Profile from './Github/Profile.jsx'; 

class App extends Component{ 
    constructor(props){ 
     super(props); 
     this.state = { 
      username: 'TedSean', 
      userData: [], 
      userRepos: [], 
      perPage: 5 
     } 
    } 
    profileData() { 
     $.ajax({ 

      url: 'https://api.github.com/users/'+this.state.username+'?client_id='+this.props.clientId+'&client_secret='+this.props.clientSecret, 
      dataType: 'json', 
      cache: false, 
      success: function(data){ 
       console.log(data); 
      }.bind(this), 
      error: function(xhr, status, err){ 
       alert(err); 
      }.bind(this) 
     }); 
    } 

    componentDidMount() { 

     this.profileData(); 
    } 
    render() { 
     return (
      <div> 
       {this.props.username} 
      </div> 
     ) 
    } 
} 

我想使用AJAX与Github API来获取配置文件数据,但不知道为什么它不工作。任何人都可以解释为什么JSON数据没有得到登录开发工具?AJAX&React:Console.log不起作用?

任何帮助,将不胜感激:)

+0

是阿贾克斯成功? – brk

+0

是Ajax成功。 – Rakzzzz

+0

componentDidMount如何被调用? – user1428716

回答

0

试试这个控制台日志

console.log('data' + data); 
+0

这是没有意义的,我通过重置开发工具来修复它。 – Rakzzzz