I want to pass the data from one js file to another js file here is my code:(react.js)
<script type="text/jsx">
/** @jsx React.DOM */
var APP=
React.createClass({
getInitialState:function(){
return{
result:[]
};
},
componentDidMount: function() {
alert("DidMount");
var data = getData();
alert("final")
},
render: function () {
alert("render");
return(
<table className="table table-bordered">
<tr>
<th>Name</th>
<th>Class</th>
<th>D.O.B</th>
</tr>
</table>
)
}
})
React.renderComponent(
<APP/>,
document.getElementById('root'));
and my js file is :
getData1=function() {
alert("initial")
var Connection = require('tedious').Connection;
var Request = require('tedious').Request;
var config = {
userName: 'zxzx',
password: '******',
server: 'xxxxxxx',// You can use 'localhost\\instance' to connect to named instance
options: {
database: 'xxxx',
rowCollectionOnRequestCompletion: true,
useColumnNames : true
}
};
var connection = new Connection(config);
connection.on('connect', function (err) {
if (err) {
console.log(err)
}
request = new Request("SELECT * FROM XXXXX", function (err, rowCount, rows) {
if (err) {
//console.log(err);
callback(err, null);
} else {
console.log(+'rows Count: ' + rowCount);
console.log(JSON.stringify(rows));
var datas = JSON.stringify(rows);
alert(datas)
alert("rows")
return datas;
}
connection.close();
});
connection.execSql(request);
});
}
what i want is that i need to return the data when calling the function in react, what happening here is that in my console it shows the data, but in react the data is coming as empty, i.e the data is not returned correctly. Can any one give solution for it?