Skip to content

Instantly share code, notes, and snippets.

@snakers4
Created January 17, 2017 07:45
Show Gist options
  • Save snakers4/39c25813d4a8d1ff146570c2948fc810 to your computer and use it in GitHub Desktop.
Save snakers4/39c25813d4a8d1ff146570c2948fc810 to your computer and use it in GitHub Desktop.
import React from 'react';
import {render} from 'react-dom';
import $ from 'jquery';
class ApiConnectors extends React.Component {
constructor (props){
super(props);
this.state = {
apiParams: props.apiParams,
apiUrl: props.apiUrl,
apiReply: '',
apiData: ''
};
}
setResults (params) {
this.setState({
apiReply : params.apiReply,
apiData : params.apiData
});
}
apiQuery () {
$.ajax({
type: "POST",
data: {"query" : this.state.apiParams},
url: this.state.apiUrl,
success: function(result) {
var jsonResult = JSON.parse(result);
let resultObject = {
apiReply:jsonResult,
apiData: jsonResult.response.data
};
this.setResults(resultObject);
}.bind(this)
})
}
render (){
this.apiQuery();
return (
<div>
{ (JSON.stringify(this.state)) }
</div>
);
}
}
export default ApiConnectors;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment