Я не знаю, что я изменил, но запрос на выборку больше не работает (только с помощью Android).Он работал раньше, пытался изменить его обратно, но не мог заставить его работать.
Я попробовал ссылки в этой проблеме: Не удалось отреагировать на собственный сетевой запрос при получении данных
Я использую правильный IP-адрес.(Взял IPv4-адрес Ipconfig для URL), как я всегда делал.Настройки разработчика на андроиде Отладка хоста и порта сервера для устройства пуста, а устройство подключено через USB-кабель.Когда я набираю IP-адрес в браузере, он показывает правильные данные JSON.
Я пытался отладить его с помощью Remote JS Debugging, но не нашел информации, почему это не удалось. пришлось добавить пробел между 'http://' ->' http: // ', потому что мне не разрешено давать много ссылок В сообщении об ошибке сказано:
Возможно необработанное обещаниеОтклонение (id: 0): ошибка типа: ошибка сетевого запроса Ошибка типа: ошибка сетевого запроса в XMLHttpRequest.xhr.onerror (blob: http: // localhost: 8081 / a0fa7e28-6cd7-4abe-899c-cb0e0ec650a8: 15827: 18) в XMLHttpRequest.dispatchEvent (blob: http: // localhost: 8081 / a0fa7e28-6cd7-4abe-899c-cb0e0ec650a8: 17904: 39) в XMLHttpRequest.setReadyState (blob: http: // localhost: 8081 / a0fa7e28-6cd7-4abe-8cb0e0ec650a8: 17659: 20) в XMLHttpRequest .__ didCompleteResponse (blob: http: // localhost: 8081 / a0fa7e28-6cd7-4abe-899c-cb0e0ec650a8: 17486: 16) в blob: http: // localhost: 8081: 8081: 8081: 80814abe-899c-cb0e0ec650a8: 17596: 47 в RCTDeviceEventEmitter.emit (blob: http: // localhost: 8081 / a0fa7e28-6cd7-4abe-899c-cb0e0ec650a8: 3482: 37) в MessageQueue .__: localfunction: blob // blob: function (blob): 8081 / a0fa7e28-6cd7-4abe-899c-cb0e0ec650a8: 2388: 44) в blob: http: // localhost: 8081 / a0fa7e28-6cd7-4abe-899c-cb0e0ec650a8: 2158: 17 в MessageQueue .__ guardSafe (большой двоичный объект: http: // localhost: 8081 / a0fa7e28-6cd7-4abe-899c-cb0e0ec650a8: 23)at MessageQueue.callFunctionReturnFlushedQueue (blob: http: // localhost: 8081 / a0fa7e28-6cd7-4abe-899c-cb0e0ec650a8: 2157: 14)
Фрагмент кода страницы, где я использую запрос на выборку:
import React, {Component} from "react";
import {
View,
Text,
StyleSheet,
TouchableHighlight,
ListView,
Image,
List,
FlatList,
} from "react-native";
import {createStackNavigator} from 'react-navigation';
import TurfLijst from './TurfPage';
var rowBackgroundColour = 'white';
var imageBackgroundColour = 'gray';
var nameBackgroundColour = '#ADD8E6'; // light blue
var borderRadius = 5;
class TurfGroupsOverview extends Component {
constructor() {
super();
const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2})
this.state = {
dataSource: ds,
user: 'None',
}
}
// fetch turflist data from the database.
componentWillMount() {
const URL = 'http://145.**.***.***:9455/group/';
console.log("Before fetching");
this.setState({loading: true});
fetch(URL, {
method: 'get',
dataType: 'json',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
}).then(response => response.json())
.then(response => {
console.log("after fetching, before saving");
this.setState({
dataSource: this.state.dataSource.cloneWithRows(response),
});
console.log("after saving to this.state");
}).catch(function(error){
console.log("ERROR OCCURED: " + error);
throw error;
});
}
renderRow(group) {
return (
<TouchableHighlight onPress={() => {
this.props.navigation.navigate('TurfPage', {
group: group,
members: group.members,
groupName: group.name
});
}
}>
<View style={[styles.boxContainer, styles.turfList]}>
<View style={styles.turfName}>
<Text>{group.name}</Text>
</View>
<View style={styles.turfPicture}>
<Image style={{width: "100%", height: "100%", borderRadius: borderRadius}}
source={({uri: group.picture})}
/>
</View>
</View>
</TouchableHighlight>
)
}
render() {
return (
<View style={styles.container}>
{console.log("Calling the render function")}
{console.log("dataSource: " + this.state.dataSource.toString())}
<ListView
dataSource={this.state.dataSource}
renderRow={this.renderRow.bind(this)}
/>
</View>
);
}
}
export default TurfGroupsOverview;
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'column',
},
boxContainer: {
height: 100,
alignItems: 'center',
justifyContent: 'center',
},
turfList: {
backgroundColor: rowBackgroundColour,
alignItems: 'center',
flexDirection: 'row',
},
turfListTwo: {
backgroundColor: 'white',
flexDirection: 'row',
},
turfName: {
backgroundColor: nameBackgroundColour,
alignItems: 'center',
justifyContent: 'center',
flex: 0.7,
height: '80%',
borderRadius: borderRadius,
},
turfPicture: {
backgroundColor: imageBackgroundColour,
alignItems: 'center',
justifyContent: 'center',
flex: 0.2,
height: '80%',
maxWidth: 80,
borderRadius: borderRadius,
}
});
Данные, которые я пытаюсь получить
[{"uuid":"68e706e1-2e47-43e6-b0b2-2cd91eba107b","name":"Group 1","picture":"http://www.israelgives.org/Pictures/AmutaPictures/5201_Large_%D7%94%D7%99%D7%93%D7%A1%D7%98%D7%90%D7%A8%D7%98%204.jpg","members":[{"uuid":"76f64769-4afa-4216-ac9e-6251da40cf50","firstName":"Ivo","lastName":"Chen","email":"ivo@ivo.nl","imageLocation":"https://thesurrianlife.files.wordpress.com/2011/07/macaque-monkey-canon-dslr-self-portrait-234x300.jpg"},{"uuid":"4d18c8dc-42a0-42fe-9cfc-223af355daaf","firstName":"Martin","lastName":"van Keulen","email":"martin@martin.nl","imageLocation":"https://s.redditmedia.com/t5_93cn9/styles/profileIcon_gsz1rsc9tc401.jpg?fit=crop&crop=faces%2Centropy&arh=1.0&w=256&h=256&s=338416408f027bd8ca437459e99dd146"}],"productList":[{"uuid":"7002648c-fbe4-40b8-9ff7-7aec01cddea1","price":1.0,"amountInStock":10,"imageLocation":null,"nameProcuct":"Hertog Jan","inStock":true},{"uuid":"be6a6b61-3726-401e-8a9c-7883e16338f2","price":1.5,"amountInStock":43,"imageLocation":null,"nameProcuct":"Heineken","inStock":true}]},{"uuid":"69b1a310-2c6d-4ed0-bb51-7cead98382fd","name":"Group 2","picture":"http://www.israelgives.org/Pictures/AmutaPictures/5201_Large_%D7%94%D7%99%D7%93%D7%A1%D7%98%D7%90%D7%A8%D7%98%204.jpg","members":[{"uuid":"feb830b4-14a6-4c40-afc9-2339726b0347","firstName":"Ivo","lastName":"Chen","email":"ivo@ivo.nl","imageLocation":"https://thesurrianlife.files.wordpress.com/2011/07/macaque-monkey-canon-dslr-self-portrait-234x300.jpg"},{"uuid":"e9b43044-6a13-473a-8259-b795215fdbcb","firstName":"Martin","lastName":"van Keulen","email":"martin@martin.nl","imageLocation":"https://s.redditmedia.com/t5_93cn9/styles/profileIcon_gsz1rsc9tc401.jpg?fit=crop&crop=faces%2Centropy&arh=1.0&w=256&h=256&s=338416408f027bd8ca437459e99dd146"}],"productList":[{"uuid":"4e45e620-a18a-4602-93d3-c3a5196a2643","price":1.0,"amountInStock":10,"imageLocation":null,"nameProcuct":"Hertog Jan","inStock":true},{"uuid":"47600a90-7614-422e-a87c-ba0d3c97bb91","price":1.5,"amountInStock":43,"imageLocation":null,"nameProcuct":"Heineken","inStock":true}]},{"uuid":"231a502a-c05f-494e-880e-bfd4b3b2f281","name":"Group 3","picture":"http://ivochen.com/wp-content/uploads/2018/08/Background_No_User.png","members":[{"uuid":"c72348fe-d838-44d4-96b2-4b20d7f68e64","firstName":"Ivo","lastName":"Chen","email":"ivo@ivo.nl","imageLocation":"https://thesurrianlife.files.wordpress.com/2011/07/macaque-monkey-canon-dslr-self-portrait-234x300.jpg"},{"uuid":"c9cf7771-a1f5-41aa-b2d7-c2e887dce2fd","firstName":"Martin","lastName":"van Keulen","email":"martin@martin.nl","imageLocation":"https://s.redditmedia.com/t5_93cn9/styles/profileIcon_gsz1rsc9tc401.jpg?fit=crop&crop=faces%2Centropy&arh=1.0&w=256&h=256&s=338416408f027bd8ca437459e99dd146"}],"productList":[{"uuid":"d206ebc9-2142-4474-9e46-f2aa133684b7","price":1.0,"amountInStock":10,"imageLocation":null,"nameProcuct":"Hertog Jan","inStock":true},{"uuid":"17e329f9-8981-41dc-b474-764bdc3ef871","price":1.5,"amountInStock":43,"imageLocation":null,"nameProcuct":"Heineken","inStock":true}]},{"uuid":"1f39a0c3-8ff2-4fe4-9e81-0480e4c51001","name":"Heren residentie Fjirma Bretels","picture":"http://ivochen.com/wp-content/uploads/2018/08/Background_No_User.png","members":[{"uuid":"95f61185-2536-4204-894c-ae5e49811312","firstName":"Ivo","lastName":"Chen","email":"ivo@ivo.nl","imageLocation":"https://thesurrianlife.files.wordpress.com/2011/07/macaque-monkey-canon-dslr-self-portrait-234x300.jpg"},{"uuid":"b396a5cb-3f30-4f27-82f3-bc102cda38ba","firstName":"Martin","lastName":"van Keulen","email":"martin@martin.nl","imageLocation":"https://s.redditmedia.com/t5_93cn9/styles/profileIcon_gsz1rsc9tc401.jpg?fit=crop&crop=faces%2Centropy&arh=1.0&w=256&h=256&s=338416408f027bd8ca437459e99dd146"}],"productList":[{"uuid":"4746ef90-9c36-45fd-87c1-a2924aa0c792","price":1.0,"amountInStock":10,"imageLocation":null,"nameProcuct":"Hertog Jan","inStock":true},{"uuid":"4059ff8b-09ed-4103-92f1-2590170d7ced","price":1.5,"amountInStock":43,"imageLocation":null,"nameProcuct":"Heineken","inStock":true}]}]
Изображение для лучшего просмотра