samedi 7 mars 2015

AJAX request in React JS js doesn't work

I'm trying to get info from my database via an AJAX request, but the success event isn't triggered.


The AJAX request is however received by the server, as it trigger the correct console log in the terminal.


I'm building it in Node, using the Express framework.


Here is the code for triggering the AJAX call. The 'componentDidMount triggered' is logged to the console. But then it stops. Neither the console.log in 'success' or 'error' is triggered, even though I know that the server has received an AJAX request.


var Main = React.createClass({ componentDidMount: function(){ console.log('componentDidMount triggered'); $.ajax({ url: "http://localhost:3000/user/per", dataType: 'json', success: function(data) { console.log('success') this.setState({data: data}); }, error: function(xhr, status, err) { console.log('error'); } });

},


I'm not getting any other errors either, so I have no idea why this isn't working.


Can anybody please help?


Aucun commentaire:

Enregistrer un commentaire