gpt4 book ai didi

php - Ionic - 应用程序可在浏览器中运行,但在移动设备中模拟时无法运行

转载 作者:搜寻专家 更新时间:2023-11-01 08:43:41 25 4
gpt4 key购买 nike

我试过这段代码

angular.module('starter', ['ionic','ngCordova'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
.controller('datactr',['$scope','$http',function($scope,$http) {
$scope.submit=function(){
console.log("step1");

$http({
method:'POST',
url:'http://awesomeg.2fh.co/updata.php',
crossDomain : true,
data:{
'name':$scope.name,
}

}).success(function(data,status,header,config){
console.log("step2");
console.log(data);
$scope.name="";
$scope.message="You have successfully updated the database";
})
}
}])

后端的 php 代码

<?php 
header('Access-Control-Allow-Origin: *' );
header('Access-Control-Allow-Credentials: true' );
header('Access-Control-Request-Method: *');
header('Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: *,x-requested-with,Content-Type');
header('X-Frame-Options: DENY');
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
$name=$request->name;
if($name){
$con=mysqli_connect('host','uname','pass','db');
$result=mysqli_query($con,"INSERT INTO userdata (name) VALUES ('$name')");
}
$out=json_encode($name);
echo"$out";
?>

我的 HTML 代码

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>

<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">

<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->

<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="js/ng-cordova.min.js"></script>
<script src="cordova.js"></script>

<!-- your app's js -->
<script src="js/app.js"></script>
<script type="js/services.js"></script>
</head>
<body ng-app="starter">

<ion-pane>
<ion-header-bar class="bar-stable">
<h1 class="title">Data Collection</h1>
</ion-header-bar>
<ion-content ng-controller="datactr">
<form role="form" ng-submit="submit()">
<label class="item item-input item-stacked-label item-divider">
Name

<input type="text" ng-model="name" placeholder="Name">
</label>
<div class="padding">
<button type="submit" class="button button-block button-positive">Submit</button>
</div>
<div class="item item-footer">
{{message}}
</div>
</form>
</ion-content>
</ion-pane>
</body>
</html>

嗯,这是基本的 ionic 应用程序,它从用户那里获取数据并将其作为 json 发送到服务器,服务器接收 json,然后处理它以在后端更新数据库。我已经在浏览器上使用

ionic serve

当我输入数据时它工作正常,它会更新数据库并给出成功更新的消息但是当我尝试在移动设备上使用

ionic run --devices

该应用程序在移动设备中打开,当我输入数据并点击提交时,没有任何反应,屏幕上的输入字段已填满。

有人可以帮忙吗?

fixed the issue by adding the following lines:

adding cordova-plugin-whitelist 

并将以下行添加到 config.xml

<access origin="*"/>
<allow-intent href="*"/>
<allow-navigation href="*"/>

最佳答案

您的代码似乎在您设备的 WebView 中抛出异常。您可以使用 Chrome 开发者工具访问设备的控制台以及桌面版 Chrome 中开发者工具提供的其他功能。

怎么做:

  • 将您的设备连接到计算机,
  • 在 Android 设备“设置”菜单的“开发者”小程序中启用“USB 调试”选项,
  • 在 Chrome 地址栏中输入以下内容:

    chrome://检查

  • 在您的 Android 设备上运行您的 Ionic 应用

  • 在“chrome://inspect”屏幕中选择您的应用

您将看到带有控制台和其他开发人员工具的应用程序屏幕。在那里您可以关注可能的 JS 异常。

关于php - Ionic - 应用程序可在浏览器中运行,但在移动设备中模拟时无法运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30411802/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com