简体   繁体   English

AJAX和React:Console.log无法正常工作吗?

[英]AJAX & React: Console.log is not working?

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>
        )
    }
}

I'm trying to use AJAX with Github API to get profile data but don't know why it is not working. 我正在尝试通过Github API使用AJAX来获取个人资料数据,但不知道为什么它不起作用。 Can anybody explain why JSON Data is not getting logged in dev tools ? 谁能解释为什么JSON数据未登录到开发工具中?

Any help would be appreciated :) 任何帮助,将不胜感激 :)

试试这个控制台日志

console.log('data' + data);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM