【问题标题】:React native Xiaomi Phone axios not working反应本机小米手机 axios 不工作
【发布时间】:2021-01-15 13:02:08
【问题描述】:

我们开发了一个带有本机反应的应用程序。 我将在下面留下应用程序的链接,我不知道这是否被禁止。 我使用 axios 提取数据,它适用于所有 android 设备。但它不适用于小米手机。我找不到原因。

const api = "apiadress/deneme.php?lesid="+getLessonId;
axios.get(api).then((response)=>{
    db.transaction((tx) => {
        tx.executeSql('UPDATE lessons SET downloaded=? WHERE id=?', ['1',getLessonId]);
    });
    response.data.map((item) => {
        db.transaction((tx) => {
            tx.executeSql('INSERT INTO questions (questionname,lessonname,answerbame,aoptionname,boptionname,coptionname,doptionname,eoptionname,lessonid,oldidq) VALUES (?,?,?,?,?,?,?,?,?,?)', 
            [item.QuestionName,item.LessonName,item.AnswerName,item.AOption,item.BOption,item.COption,item.DOption,item.EOption,item.id,item.Id]);
        });
    });
    console.log("Tüm sorular başarıyla kayıt edildi.");
});

代码的图像

link

【问题讨论】:

    标签: android react-native mobile mobile-application xiaomi


    【解决方案1】:

    我不确定是什么问题,但是我在使用 axios 时遇到了类似的问题(部署后服务器请求不起作用)

    你应该考虑离开 axios 并尝试使用 fetch:

    发布:

    fetch('http://mywebsite.com/endpoint/', {
          method: "POST",
          headers: {
            // Authorization: "Bearer " + Token,
            Accept: 'application/json',
          'Content-Type': 'application/json'
          },
          body: JSON.stringify({
           // sending data userID username, password, etc
          }),
        })
          .then((response) => response.json())
          .then((responseJson) => {
           // Response will here
          })
          .catch((error) => {
            alert(error);
          });
    

    获取:

    fetch('http://mywebsite.com/endpoint/', {
          method: "GET",
          headers: {
           // Authorization: "Bearer " + Token,
           // OR USER name PASSworrd
           Accept: 'application/json',
          'Content-Type': 'application/json'
          },
        })
          .then((response) => response.json())
          .then((responseJson) => {
    
            // Response will here
          })
          .catch((error) => {
            alert(error);
          });
    

    【讨论】:

      猜你喜欢
      • 2021-01-14
      • 2018-08-30
      • 1970-01-01
      • 1970-01-01
      • 2022-12-18
      • 2016-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多