No Description

fetchData.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import * from styles
  2. import DropDownPicker from 'react-native-dropdown-picker';
  3. import React, {useState, useEffect} from 'react';
  4. //ALL REQUIRED TO GET DATA
  5. DropDownPicker.setListMode("SCROLLVIEW")
  6. //data parsing goes here
  7. function getInfo(information){
  8. //console.log(information[6])
  9. if(!information)
  10. {Alert.alert("Please try again later! Error retriving data")}
  11. else
  12. {return information}
  13. }
  14. //data display
  15. class DataButton extends React.Component{
  16. state = {
  17. click: false
  18. }
  19. pullData = () => {createQuery(pueblo, table); information = loadDoc(query); this.setState({click: true})}
  20. render() {
  21. return(
  22. <View>
  23. <Button
  24. onPress = {this.pullData}
  25. title = "Fetch Data"
  26. color = "black"
  27. />
  28. <Text style={styles.sub}>{getInfo()}</Text>
  29. </View>
  30. );}
  31. }
  32. function createQuery(pueblo, table) {
  33. console.log("fetching data")
  34. var query = "http://127.0.0.1:5378/table?table=" table + "&municipality=" + pueblo
  35. if(pueblo && table)
  36. {return query}
  37. else
  38. {Alert.alert("Please fill every parameter before calling!")}
  39. }
  40. function loadDoc(query) {
  41. var xhttp = new XMLHttpRequest();
  42. xhttp.onreadystatechange = function() {
  43. if (this.readyState == 4 && this.status == 200) {
  44. var information = this.responseText;
  45. return information
  46. }
  47. };
  48. xhttp.open("GET", query, true);
  49. xhttp.send();
  50. }