Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //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.
- //Section 1 Starts Here
- var Orderlist = React.createClass({
- Order_list: function(){
- $.ajax({
- type: 'GET',
- url: "/order/list/10/1",
- headers: {
- Accept : "application/json",
- "Content-Type": "application/json"
- },
- success: function(orderlist) {
- // console.log(orderlist);
- // console.log(this.state.orderlist);
- this.setState({orderlist: orderlist}, function(){
- console.log(this.state.orderlist);
- }.bind(this));
- }.bind(this),
- error: function(xhr, status, err) {
- // console.error(this.props.url, status, err.toString());
- }.bind(this)
- });
- },
- getInitialState: function(){
- return{
- orderlist : []
- };
- },
- componentDidMount: function(){
- this.Order_list();
- // setInterval(this.Order_list, 10000);
- },
- render: function(){
- var orderlist11 = [];
- for(var ordernum in this.state.orderlist){
- orderlist11.push(<div className="card">
- <div className="title">
- Order Number {this.state.orderlist[ordernum].ordernumber} </div>
- <div className="content"> Date & Time : {this.state.orderlist[ordernum].bizorderdate} <br />
- Username : {this.state.orderlist[ordernum].userid}
- </div>
- </div>);
- }
- return (
- <div >
- {orderlist11}
- </div>
- );
- }
- });
- ////// Section 1 ends here
- var RefreshToken = React.createClass({
- getInitialState : function(){
- return {
- token : -1 //Or anything that is not a token.
- }
- },
- componentDidMount : function(){
- setInterval(this.refresh_token, 10000);
- },
- refresh_token : function(){
- var self = this;
- $.ajax({
- type: 'GET',
- url: "/order/refresh",
- headers: {
- Accept : "application/json",
- "Content-Type": "application/json"
- },
- success: function (resp){
- var newToken = resp;
- console.log(newToken); //it give the value of refresh eg. ["20150925313"]
- if(newToken != self.state.token){
- self.setState({ token: newToken});
- // console.log(this.state.resp);
- }
- }
- });
- },
- shouldComponentUpdate: function(nextProps, nextState) {
- return true;
- },
- render: function(){
- var order_list_new;
- // var token33 = this.refresh_token();
- var a = this.state.token;
- var b = this.state.timenow;
- console.log(a);
- console.log(b);
- var diff = b - a;
- // console.log(diff);
- if( diff > 1 )
- {
- order_list_new = <Orderlist />;
- }
- return (
- <div>
- {order_list_new}
- </div>
- );
- }
- });
- React.render(
- <RefreshToken />,
- document.getElementById('list_of_orders')
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement