小编use*_*367的帖子

在Android上反应Native,使用fetch的ajax调用失败

我正在使用React Native开发Android应用程序.我正在使用在Mac上运行的Android Studio中模拟的Galaxy Nexus API 23上测试我的应用.

我希望允许用户彼此共享信息.我正在运行一个带有php和mysql的web服务器,我希望应用程序向服务器发出请求,以便在用户之间共享数据.

我正在尝试使用Fetch API向我的开发服务器发出POST请求.我的js代码如下:

var AjaxEngine = {
    test: function() {
            return fetch('http://10.0.2.2/test.json')
                .then((response) => response.json())
                .then((responseJson) => {
                    console.log(responseJson);
                    return responseJson.movies;
                })
                .catch((error) => {
                    console.error(error);
                });
        }
};
Run Code Online (Sandbox Code Playgroud)

叫做 AjaxEngine.test();

在我的模拟器中,我收到以下错误:

ExceptionsManager.js:70 TypeError:XMLHttpRequest.xhr.onerror(http:// localhost:8081/index.android.bundle?platform = android&dev = true&hot = false&minify = false:23711:8)的XMLHttpRequest.dispatchEvent 网络请求失败(http:// localhost:8081/index.android.bundle?platform = android&dev = true&hot = false&minify = false:9740:15)XMLHttpRequest.setReadyState(http:// localhost:8081/index.android.bundle?platform = android&dev =真热=假缩小=假:25157:6)在XMLHttpRequest的.__ didCompleteResponse(HTTP://本地主机:8081/index.android.bundle平台=机器人&dev的=真热=假缩小=假:25015:6)在HTTP://本地主机:8081/index.android.bundle?platform = android&dev = true&hot = false&minify = …

ajax android android-emulator react-native fetch-api

6
推荐指数
1
解决办法
962
查看次数