I have a problem with my reactjs code. I've read the thread about the async world and the problems that can occur and I think I fix that, but now I get a blank with a text of Cannot GET /thenameofthepage.
This is my code right after the react.Component
getList() {
var returnValue;
$.ajax({
type: "get",
url: "###URL###",
cache: false,
async: false,
success : function(data) {
returnValue = data;
}
});
return returnValue;
}
and this is the code right after render() {
console.log(this.getList());
If I console log in the function then everything is okay. But when I try to pass it to a variable everything breaks. I did async. Not working. I tried with initial states and ComponentDidMount() again not working.
P.S
I tried by using internet guide:
constructor() {
this.state = { data: [] };
}
getList() {
$.ajax({
type: "get",
url: "http://havvamustafa.devel.signature.eu.com/manage/collection/list_all_ajax",
cache: false,
dataType: 'json',
success: (data) => {
this.setState({data: data});
}
});
}
Then
componentDidMount() {
this.getList();
}
And in the end
console.log(this.state.data);
Now it gives me error because of the constructor.