javascript - Axios请求在iOS上显示响应,但不适用于android

标签 javascript android ios react-native axios

我正在使用axios在React native中将一些数据发布到服务器,但是我遇到了一个问题,我的代码在IOS中运行良好,但是我在android情况下遇到了一些问题。这是我的代码,看看吧。

login = () => {
    const { username, password } = this.state;
    let reg = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
    if (username == "") {
      //alert("Please enter Email address");
      this.setState({ email: "Please enter Email address" });
    } else if (reg.test(username) === false) {
      //alert("Email is Not Correct");
      this.setState({ email: "Email is Not Correct" });
      return false;
    } else if (password == "") {
      this.setState({ email: "Please enter password" });
    } else {
      this.openProgressbar();
      axios
        .post(
          CONSTANT.BaseUrl + "user/do-login",
          {
            email: username,
            password: password
          }
        )
        .then(async (response) => {
          if (response.data.type == "success") {
            await AsyncStorage.setItem(
              "full_name",
              response.data.profile.pmeta.full_name
            );
            await AsyncStorage.setItem(
              "user_type",
              response.data.profile.pmeta.user_type
            );
            await AsyncStorage.setItem(
              "profile_img",
              response.data.profile.pmeta.profile_img
            );
            await AsyncStorage.setItem(
              "profileBanner",
              response.data.profile.pmeta.banner_img
            );
            await AsyncStorage.setItem(
              "profileType",
              response.data.type
            );
            await AsyncStorage.setItem(
              "projectUid",
              response.data.profile.umeta.id
            );
            await AsyncStorage.setItem(
              "projectProfileId",
              JSON.stringify(response.data.profile.umeta.profile_id)
            );
            this.setState({ isProgress: false })
            RNRestart.Restart();
          } else if (response.data.type == "error") {
            this.setState({ isProgress: false });
            alert("Please Check Your Email / Password or Check Network ");
          }
        })
        .catch(error => {
          console.log(error);
        });
    }
    Keyboard.dismiss();
  };

在IOS情况下,它在响应后以.then进行移动,而在ANDROID中则以.catch进行移动

最佳答案

请从此更改链接:
response.data.profile.umeta.id
对此:JSON.stringify(response.data.profile.umeta.id)
我认为那应该为您完成工作。

关于javascript - Axios请求在iOS上显示响应,但不适用于android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60389447/

相关文章:

c# - 在 C# 和 ASP.NET 的 javascript 警报中使用 %s

android - 尝试在核心库以外的对象中包含核心类(java.* 或 javax.*)

ios - 如何在嵌套的 Realm 列表中创建新对象?父对象应保持不变,但必须将其 "holds"添加到列表中

Android Action Bar (Sherlock Action Bar) - 将下拉微调器一直定位到右侧

ios - 为什么retainCount返回2

ios - 是否可以排除具有最新日期的对象?

javascript - 避免同时具有 css 和 js 依赖项的插件渲染阻塞

javascript - 无法使用 webpack 将 Base64 图像导入到 React 组件中

javascript - 如何将 $.each 循环中的结果相加?

jquery - Android Honeycomb 有一个反转的 event.orientation 值?