How to fix “Error: XMLHttpRequest failed” on React Native with Parse-Server backend

妖精的绣舞 提交于 2020-03-25 13:42:36

问题


Today I have a plan to convert an iOS app (Swift) and Android (Java+Kotlin) to React Native. This app show hospital as Marker on (Google)Maps based on user location. My backend is Parser-Server (now is ParsePlatform)

The function bellow query the data (class) from Parse backend:

async getHospitalNearbyUser() {
        const { userLocation, region } = this.state
        if ((userLocation.lat !== null) && (userLocation.lng !== null)) {
            const lng = userLocation.lng
            const lat = userLocation.lat
            const radius = 1.0

            let lng_min = lng - radius / Math.abs(Math.cos(this.deg2rad(lat)) * 69)
            let lng_max = lng + radius / Math.abs(Math.cos(this.deg2rad(lat)) * 69)

            let lat_min = lat - (radius / 69)
            let lat_max = lat + (radius / 69)

            // query
            const atm = Parse.Object.extend('Hospital')
            let query = new Parse.Query(atm)
            query.greaterThan("lat", lat_min)
            query.lessThan("lat", lat_max)
            query.greaterThan("lng", lng_min)
            query.lessThan("lng", lng_max)

            query.find()
                .then(function (results) {
                    console.debug(results.length)
                })
                .catch(function (error) {
                    // There was an error.
                    console.error(error)
                })
        } else {
            console.debug('no location')
            console.debug(region)
        }
    }

However the error shows up is:

Error: XMLHttpRequest failed: {"line":169557, "column:32", "sourceURL":"http://localhost:8081/index.bundle?platform=ios&dev=true&minifiy=false"

I tried to seach on Google and Parse SDK-JS on github issues but no results.

Hope some help from you.

Thanks so much !

// Update: I am using Parse-Server that is hosted at Back4App.


回答1:


I had the same problem,

I fixed this by changing

import {AsyncStorage} from '@react-native-community/async-storage';

to

import {AsyncStorage} from 'react-native';


来源:https://stackoverflow.com/questions/60235805/how-to-fix-error-xmlhttprequest-failed-on-react-native-with-parse-server-back

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!