本文介绍了intel-xdk html5平台android应用程序在模拟器中正常工作但在设备中无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用javascript函数getApi()包含了一个php文件,它在我的intel-xdk模拟器中正常工作但是当我将它加载到我的Android设备时它将无法正常工作
所以请求告诉我有什么问题我的代码,我的设备也与互联网连接,因此它可以从服务器检索数据,但它不能

b
$ b

I have included a php file using javascript function getApi() it working properly in my intel-xdk emulator but when i load it in to my android device it will not working properly so pleas tell me what's wrong with my code , and my device is also connected with internet so it may able to retrive data from the server ,but it can't

<head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  <link rel="stylesheet" type="text/css" href="app_framework/css/af.ui.min.css">
  <link rel="stylesheet" type="text/css" href="app_framework/css/icons.min.css">
  <meta charset="UTF-8">
  <link rel="stylesheet" type="text/css" href="css/index_main.less.css" class="main-less">
  <title>Your New Application</title>
  <meta http-equiv="Content-type" content="text/html; charset=utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
  <style type="text/css">
    /* Prevent copy paste for all elements except text fields */
    *  { -webkit-user-select:none; -webkit-tap-highlight-color:rgba(255, 255, 255, 0); }
    input, textarea  { -webkit-user-select:text; }
  </style>
  <script src="intelxdk.js">
</script>
  <script type="text/javascript">
    /* This code is used to run as soon as Intel activates */
    var onDeviceReady=function(){
      //hide splash screen
      intel.xdk.device.hideSplashScreen();
    };
    document.addEventListener("intel.xdk.device.ready",onDeviceReady,false);
  function getApi() {
                           alert("Yes");
                            $.ajax({
                            type: "GET",
                            url: "http://exam.coreducation.in/api.php",
    success: function(data){
var total = "";
var record = JSON.parse( data );
for(i=0; i<record.length; i++){
total += ("Contact: "+record[i]['contact']+", Name: "+record[i]['name']+", City: "+record[i]['city'] + "<br/>");
}
$('#ddata').html("<h4 style='text-align:center'>"+total+"</h4>")
    }
  });
}    
    </script>
  <script type="application/javascript" src="app_framework/appframework.min.js"></script>
  <script type="application/javascript" src="app_framework/appframework.ui.min.js"></script>
</head>

<body id="afui">

  <!-- content goes here-->
  <div class="uwrap" id="content">
    <div class="upage panel" id="page0" data-header="none" data-footer="none">
      <div class="upage-outer">
        <div class="upage-content">

          <div class="grid grid-pad urow uib_row_1 row-height-1" data-uib="layout/row">
            <div class="col uib_col_1 col-0_12-12" data-uib="layout/col">
              <div class="widget-container content-area vertical-col">

                <a class="button widget uib_w_1 d-margins icon graph" data-uib="app_framework/button" onclick="return getApi();">GetApiData</a><span class="uib_shim">
                  </span>
            <div id="ddata">DAta Will Show Here</div>
                </div>
            </div>
            <span class="uib_shim"></span>
          </div>
        </div>
        <!-- /upage-content -->

      </div>
      <!-- /upage-outer -->

    </div>


  </div>
  <!-- /uwrap -->
</body>

</html>`enter code here`


推荐答案

由于跨域访问,api被阻止,这也是您的代码无法在任何浏览器中运行的原因。但是有一种方法可以让它在英特尔XDK应用程序中运行,只需在你的intelxdk之后添加< script src =xhr.js>< / script> 。 js脚本包含。然后它将在设备上工作。

The api is blocked due to Cross domain access, same reason why your code will not work in any browser. But there is a way to make it work in Intel XDK apps, just add <script src="xhr.js"></script> after your intelxdk.js script inclusion. It will then work on device.

更多关于AJAX和XDK的信息:

More info about AJAX and XDK here: http://software.intel.com/en-us/html5/articles/how-to-access-JSON-data-in-HTML5-apps

这篇关于intel-xdk html5平台android应用程序在模拟器中正常工作但在设备中无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 07:19