javascript - 如何在 ionic 中的 app.run() 中包含 HTTP 请求

标签 javascript android ios cordova

我用 ionic V1 制作了 android 项目。我想让应用程序在使用 Cordova event 关闭应用程序之前发送一些功能。我尝试使用暂停将数据发送到服务器,但我一直坚持在 app.run() 中发送数据。这是我在 app.js

中的代码
.run(function ($ionicPlatform) { 
   $ionicPlatform.ready(function () { 
      document.addEventListener("pause", onPause, false);
   }); 
   function onPause($http) {
    $http.get('https://localhost:88/web.php?tN=off&f12=123456789')
    .then(function(response){
         console.log(response);
    }, function(error){
         //there was an error fetching from the server
    });
   }
});

还有这个来自调试器的错误

Uncaught TypeError: Cannot read property 'get' of undefined

我不知道这段代码哪里出了问题。我在 controller.js 中使用它可以正常工作,但在 app.js 中它不起作用。请帮我解决这个问题。谢谢

最佳答案

$http 缺少的是你的 run() 参数

关于javascript - 如何在 ionic 中的 app.run() 中包含 HTTP 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45161789/

相关文章:

javascript - 单击按钮后如何清除backbone.js 中的文本字段?

javascript - javascript 或 angularjs 中的 PHP microtime()

ios - 在单元格中加载时隐藏/显示@IBOUlet @IBAction

ios - 在 for 语句中使用 String.CharacterView.Index.successor()

javascript - 尝试单击下拉列表中的链接,该链接只能通过将鼠标悬停在元素上来访问

javascript - 使用 jQuery load() 和 pushState() 模拟帧

android - ListView中的checkbox 'Checked'滚动后恢复

android edittext单击按钮后删除焦点

java - For Loop 延迟不工作 Android

ios - UIViewController 自定义后退导航按钮