Ajax Call在使用IONIC的移动设备中无效

Sak*_*and 5 javascript cordova ionic-framework

我创建了离子应用程序,我在浏览器中运行应用程序工作正常.但我尝试在移动设备上运行的同一个应用程序AJAX调用不起作用.在ajax我发出警报之前,它已被填充.以下是我的代码.

代码是,

$http({
        method: 'POST', 
        //url: syncURL,
        url:"http://45.xx.xxx:8080/MobileSync/SummaTest/update_SummaNoun",
        data: surveyResultrecords,//surveyResultrecords 
         }).then(function(result){
                            console.log( "yay---" +JSON.stringify(result.data));
                            alert("yay");
                            alert("APTAM");
                                            //$scope.SummaNoun.id = surveyResultrecords.id;  
                                            //var promise1 = imageUpload(); 
                                            //console.log("PUSH completed ");
                                            //alert("test---finished");
                                            return "data Updated";//imageUpload();

                        }).then(function(ress){
                                console.log("PUSH completed ");
                                alert("push completed")
                        });
Run Code Online (Sandbox Code Playgroud)

这些是我安装的cordova插件,

"cordovaPlugins": [
    "cordova-plugin-camera",
    "cordova-plugin-device",
    "cordova-plugin-console",
    "cordova-plugin-splashscreen",
    "cordova-plugin-statusbar",
    "ionic-plugin-keyboard",
    "cordova-plugin-whitelist",
    "cordova-plugin-file",
    "cordova-plugin-file-transfer"
  ]
Run Code Online (Sandbox Code Playgroud)

config.xml中

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="com.ionicframework.Testcamera10008" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
  <name>testCamera</name>
  <description>
        An Ionic Framework and Cordova project.
    </description>
  <author email="you@example.com" href="http://example.com.com/">
      Your Name Here
    </author>
  <content src="index.html"/>
  <preference name="webviewbounce" value="false"/>
  <preference name="UIWebViewBounce" value="false"/>
  <preference name="DisallowOverscroll" value="true"/>
  <preference name="SplashScreenDelay" value="2000"/>
  <preference name="FadeSplashScreenDuration" value="2000"/>
  <preference name="android-minSdkVersion" value="16"/>
  <preference name="BackupWebStorage" value="none"/>
  <preference name="SplashScreen" value="screen"/>
  <feature name="StatusBar">
    <param name="ios-package" value="CDVStatusBar" onload="true"/>
  </feature>
  <platform name="android">
    <allow-intent href="market:*"/>
    <allow-intent href="*"/>
    <allow-navigation href="*"/>
    <access origin="*"/>
    <icon src="resources/android/icon/drawable-ldpi-icon.png" density="ldpi"/>
    <icon src="resources/android/icon/drawable-mdpi-icon.png" density="mdpi"/>
    <icon src="resources/android/icon/drawable-hdpi-icon.png" density="hdpi"/>
    <icon src="resources/android/icon/drawable-xhdpi-icon.png" density="xhdpi"/>
    <icon src="resources/android/icon/drawable-xxhdpi-icon.png" density="xxhdpi"/>
    <icon src="resources/android/icon/drawable-xxxhdpi-icon.png" density="xxxhdpi"/>
    <splash src="resources/android/splash/drawable-land-ldpi-screen.png" density="land-ldpi"/>
    <splash src="resources/android/splash/drawable-land-mdpi-screen.png" density="land-mdpi"/>
    <splash src="resources/android/splash/drawable-land-hdpi-screen.png" density="land-hdpi"/>
    <splash src="resources/android/splash/drawable-land-xhdpi-screen.png" density="land-xhdpi"/>
    <splash src="resources/android/splash/drawable-land-xxhdpi-screen.png" density="land-xxhdpi"/>
    <splash src="resources/android/splash/drawable-land-xxxhdpi-screen.png" density="land-xxxhdpi"/>
    <splash src="resources/android/splash/drawable-port-ldpi-screen.png" density="port-ldpi"/>
    <splash src="resources/android/splash/drawable-port-mdpi-screen.png" density="port-mdpi"/>
    <splash src="resources/android/splash/drawable-port-hdpi-screen.png" density="port-hdpi"/>
    <splash src="resources/android/splash/drawable-port-xhdpi-screen.png" density="port-xhdpi"/>
    <splash src="resources/android/splash/drawable-port-xxhdpi-screen.png" density="port-xxhdpi"/>
    <splash src="resources/android/splash/drawable-port-xxxhdpi-screen.png" density="port-xxxhdpi"/>
  </platform>
</widget>
Run Code Online (Sandbox Code Playgroud)

的index.html

<!DOCTYPE html>
<html lang="en" >
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <meta http-equiv="Content-Security-Policy">
    <title>Testcamera</title>

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

    <script src="lib/ionic/js/ionic.bundle.js"></script><script src="lib/ngCordova/dist/ng-cordova.min.js"></script>
    <script src="cordova.js"></script>
    <script src="app/js/app.js"></script>
    <script src="lib/jquery/jquery-2.1.3.min.js"></script>
    <script src="lib/ionic-datepicker/dist/ionic-datepicker.bundle.min.js"></script>
    <script src="app/js/controllers/AplicationLevelCtrl.js"></script>
    <script src="app/js/controllers/SummaTest.js"></script>
    <script src="app/js/controllers/SummaNoun_Default_Activity.js"></script>

<body ng-app="Testcamera">
    <ion-nav-view></ion-nav-view>
</html>
Run Code Online (Sandbox Code Playgroud)

Chrome Inspecter图片 针对该ajax调用的Chrome Inspecter在浏览器中工作,供您参考

我安装了cordova-whitelist插件,也是我的cordova版本6.2.0,离子1.7.16.

小智 0

为什么你的 config.xml 中没有插件声明,例如:

<plugin name="cordova-plugin-whitelist" spec="~1.2.2" />
Run Code Online (Sandbox Code Playgroud)

而你没有这个标签:

<access origin="*" subdomains="true" />
Run Code Online (Sandbox Code Playgroud)

阅读此处了解更多相关信息

另外,这篇文章可能会对您有所帮助。祝你好运