Advertisement
amitbondwal

Uncaught TypeError: Cannot read property 'token' of undefine

Sep 24th, 2015
810
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.33 KB | None | 0 0
  1. //In this code, I am trying to do when the value of ajax refresh_token function changed the Orderlist function should call. But I am not able to do this.
  2.  
  3.  
  4.  
  5. //Section 1 Starts Here
  6. var Orderlist = React.createClass({
  7.  
  8. Order_list: function(){
  9. $.ajax({
  10. type: 'GET',
  11. url: "/order/list/10/1",
  12. headers: {
  13. Accept : "application/json",
  14. "Content-Type": "application/json"
  15. },
  16.  
  17. success: function(orderlist) {
  18. // console.log(orderlist);
  19. // console.log(this.state.orderlist);
  20.  
  21. this.setState({orderlist: orderlist}, function(){
  22. console.log(this.state.orderlist);
  23. }.bind(this));
  24.  
  25. }.bind(this),
  26. error: function(xhr, status, err) {
  27. // console.error(this.props.url, status, err.toString());
  28. }.bind(this)
  29.  
  30. });
  31. },
  32.  
  33. getInitialState: function(){
  34. return{
  35. orderlist : []
  36. };
  37. },
  38.  
  39. componentDidMount: function(){
  40. this.Order_list();
  41. // setInterval(this.Order_list, 10000);
  42. },
  43.  
  44. render: function(){
  45. var orderlist11 = [];
  46. for(var ordernum in this.state.orderlist){
  47. orderlist11.push(<div className="card">
  48. <div className="title">
  49. Order Number {this.state.orderlist[ordernum].ordernumber} </div>
  50. <div className="content"> Date & Time : {this.state.orderlist[ordernum].bizorderdate} <br />
  51. Username : {this.state.orderlist[ordernum].userid}
  52. </div>
  53. </div>);
  54.  
  55.  
  56. }
  57. return (
  58. <div >
  59. {orderlist11}
  60. </div>
  61. );
  62. }
  63. });
  64.  
  65. ////// Section 1 ends here
  66.  
  67.  
  68. var RefreshToken = React.createClass({
  69.  
  70. getInitialState : function(){
  71. return {
  72. token : -1 //Or anything that is not a token.
  73. }
  74. },
  75.  
  76. componentDidMount : function(){
  77.  
  78. setInterval(this.refresh_token, 10000);
  79. },
  80.  
  81. refresh_token : function(){
  82. var self = this;
  83. $.ajax({
  84. type: 'GET',
  85. url: "/order/refresh",
  86. headers: {
  87. Accept : "application/json",
  88. "Content-Type": "application/json"
  89. },
  90.  
  91. success: function (resp){
  92. var newToken = resp;
  93. console.log(newToken); //it give the value of refresh eg. ["20150925313"]
  94.  
  95. if(newToken != self.state.token){
  96.  
  97. self.setState({ token: newToken});
  98. // console.log(this.state.resp);
  99. }
  100. }
  101. });
  102. },
  103.  
  104. shouldComponentUpdate: function(nextProps, nextState) {
  105. return true;
  106. },
  107.  
  108.  
  109.  
  110. render: function(){
  111.  
  112. var order_list_new;
  113. // var token33 = this.refresh_token();
  114. var a = this.state.token;
  115. var b = this.state.timenow;
  116. console.log(a);
  117. console.log(b);
  118.  
  119. var diff = b - a;
  120. // console.log(diff);
  121. if( diff > 1 )
  122. {
  123. order_list_new = <Orderlist />;
  124. }
  125.  
  126.  
  127. return (
  128. <div>
  129.  
  130. {order_list_new}
  131. </div>
  132. );
  133. }
  134.  
  135. });
  136.  
  137.  
  138. React.render(
  139. <RefreshToken />,
  140. document.getElementById('list_of_orders')
  141. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement