Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/477.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript TypeError:无法读取属性';邮政';“无效”的定义;_Javascript_Jquery_Ajax_Api_Reactjs - Fatal编程技术网

Javascript TypeError:无法读取属性';邮政';“无效”的定义;

Javascript TypeError:无法读取属性';邮政';“无效”的定义;,javascript,jquery,ajax,api,reactjs,Javascript,Jquery,Ajax,Api,Reactjs,我刚开始使用React,当我尝试进行Ajax调用时,遇到了一些麻烦 我得到: 内联JSX脚本:29Uncaught TypeError:无法读取null的属性“post” 我不知道为什么我会出错 我已经测试过,如果我将:{this.state.post}从渲染函数中移除,则警报(数据)正确响应 谁能帮帮我吗 <script type="text/jsx"> var SomeComponent = React.createClass({

我刚开始使用React,当我尝试进行Ajax调用时,遇到了一些麻烦

我得到:

内联JSX脚本:29Uncaught TypeError:无法读取null的属性“post”

我不知道为什么我会出错

我已经测试过,如果我将:
{this.state.post}
从渲染函数中移除,则
警报(数据)
正确响应

谁能帮帮我吗

   <script type="text/jsx">

        var SomeComponent = React.createClass({

            render: function(){
                return(
                            <h3>{this.props.header}</h3>
                    );
            }
        });

        React.render( <SomeComponent header="Dette er en tittel :)"/>, document.getElementById('content'));

        var EinarsComponent = React.createClass({

            componentDidMount: function(){
            $.ajax({
                url: "https://api.bring.com/shippingguide/api/postalCode.html",
                data: {clientUrl: "localhost", pnr: "4879"},
                success: function(data){
                    this.setState({post: data});
                    alert(data);
                }.bind(this)    
            });
        },
            render: function(){

                return(         
                        <div>{this.state.post}</div>
                    );
            }
        });

        React.render(<EinarsComponent />, document.getElementById('hei'));
    </script>

var SomeComponent=React.createClass({
render:function(){
返回(
{this.props.header}
);
}
});
React.render(,document.getElementById('content'));
var EinarsComponent=React.createClass({
componentDidMount:function(){
$.ajax({
url:“https://api.bring.com/shippingguide/api/postalCode.html",
数据:{clientUrl:“localhost”,pnr:“4879”},
成功:功能(数据){
this.setState({post:data});
警报(数据);
}.绑定(此)
});
},
render:function(){
报税表(
{this.state.post}
);
}
});
React.render(,document.getElementById('hei'));

组件的初始状态从未设置,默认为
null
。在组件中添加函数
getInitialState

getInitialState: function(){
  return {
    post: null // Or some other default value that you fancy
  };
}