Created
January 17, 2017 07:45
-
-
Save snakers4/39c25813d4a8d1ff146570c2948fc810 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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