Home React state update in ajax success
Reply: 0

React state update in ajax success

user1351
1#
user1351 Published in April 26, 2018, 1:46 pm

I'm having problems with setting my state when a ajax call is successfully run. I want to update the state when the ajax process is completed. The text in the div stays on "Busy" instead of "Done", while in the browser Network Tab, I see the status changing from "pending" to status "200".

import React, { Component } from "react";
import * as ReactDOM from "react-dom";
import { extend } from "lodash";

export class StoreToCheck extends React.Component{
  constructor(props){
    super(props);
    this.state = { ListWithISBN :[],
                   getISBNS : false };
    this.ajaxSuccess = this.ajaxSuccess.bind(this);
  }
  getISBNSList(){
    if(!this.state.getISBNS){
      var store_name;
      // loop through array to fill store_name variable

      var ajaxSuccess = this.ajaxSuccess;
      if(store_name != ''){
        apex.server.process(
          'GET_EBOOKS_FROM_STORE',
          {
            success:function (data){
              // when succesfull update state getISBNS
              ajaxSuccess
            }
          }
        );
      }
    }
  }
  ajaxSuccess(){
    this.setState({"getISBNS":true});
  }
  componentDidMount(){
    this.getISBNSList();
  }
  render(){
    return(
      <div>
          {this.state.getISBNS ? "Done" : "Busy"}
      </div>
    )
  }
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.441118 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO