Apache cordova apk doesn't run properly on android

前提是你 提交于 2021-02-04 06:55:28

问题


I am using ajax to access a php file.

$.ajax({
    type:"post",
    url: "http://192.168.0.111/hetazotakan/read.php",
    success: function(result){
    var data=JSON.parse(result);
    console.log(data);
    var place=document.getElementById("news_space");
    for(var i=data.length-1;i>=0;i--){
        place.innerHTML+=`<li class="one_third">
          <article><a href="#"><img src="${data[i].photo}"       style="height:240px;width:320px;" alt=""></a>
            <h6 class="heading">${data[i].title}</h6>
            <ul class="nospace meta">
              <li><i class="fa fa-user"></i> <a href="#">Admin</a></li>
              <li><i class="fa fa-tag"></i> <a href="#">${data[i].date}</a></li>
            </ul>
            <p>${data[i].body.slice(1, 100)+"..."}</p>
            <footer class="nospace"><a class="btn" id="news_${data[i].id}" onclick="open_news(this.id)">Full Story &raquo;</a></footer>
          </article>
        </li>`;
    }
  },
    error:function(){alert(2);}
});

When I run it with the browser it works, today I tried to run it on android, but the success function didn't work, instead it alerted 2. I have installed cordova-plugin-whitelist to my project and tried to give it access to the IP address, but it didn't work. Here's the config file.

<?xml version='1.0' encoding='utf-8'?>
<widget id="io.cordova.hellocordova" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>HelloCordova</name>
    <description>
        A sample Apache Cordova application that responds to the deviceready event.
    </description>
    <author email="dev@cordova.apache.org" href="http://cordova.io">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <access origin="*" />
<access origin="*" />
<allow-navigation href="*"/>
    <access origin="http://192.168.0.111" />
    <access origin="http://192.168.0.111/*/*" />
    <allow-intent href="http://localhost" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <platform name="android">
    <access origin="*" />
<allow-navigation href="*"/>
    <access origin="http://192.168.0.111" />
    <access origin="http://192.168.0.111/*/*" />
        <allow-intent href="market:*" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
</widget>

I don't know what else to do, when I access the 192.168.0.111/Hetazotakan/read.php address on my android device on google it works. The deadline is in less then 12 hours, help me if you can.


回答1:


192.168.0.111 is a local network address. Unless you plan to always run your app while connected to your local network, it wouldn't work in the real world. Consider a domain name.



来源:https://stackoverflow.com/questions/65761350/apache-cordova-apk-doesnt-run-properly-on-android

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