gpt4 book ai didi

javascript - 设备模式下 Web API 调用失败

转载 作者:行者123 更新时间:2023-12-03 10:34:18 25 4
gpt4 key购买 nike

我已经在 Cordova (VS2015) 中实现了小型移动应用程序。在我的应用程序中,我使用 asp.net wep api 获取所有必需的数据。我的移动解决方案在纹波模拟器中运行良好。但不能在设备模式(Andorid)下工作。我已经发布了我的 Web 服务和本地 IIS 服务器,并且我使用本地 IP 地址和端口号来访问它。另外,我也在我的 Web api 中启用了跨域调用。

下面是我使用 angularJS 实现的 app.js 查找和服务。

var app = angular.module('RandBApp', ['ionic', 'RandBApp.controllers'])

.run(函数($ionicPlatform) { $ionicPlatform.ready(函数 () { if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) { cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); } if (窗口.StatusBar) { StatusBar.styleDefault(); } });})

.config(函数($compileProvider,$stateProvider,$urlRouterProvider,$httpProvider){

$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|ghttps?|ms-appx|x-wmapp0):/);
$compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|ftp|file|ms-appx|x-wmapp0):|data:image\//);

$stateProvider

.state('app', {
url: "/app",
abstract: true,
templateUrl: "app/views/menu.html",
controller: 'RandBAppCtrl'
})

.state('app.products', {
url: "/products",
cache: false,
views: {
'menuContent': {
templateUrl: "app/views/products.html",
controller: 'ProductsCtrl'
}
}
})

.state('app.productdetail', {
url: "/products/:productid",
views: {
'menuContent': {
templateUrl: "app/views/productdetail.html",
controller: 'ProductDetailCtrl'
}
}
})

.state('app.signup', {
url: "/signup",
cache: false,
views: {
'menuContent': {
templateUrl: "app/views/signup.html",
controller: 'SignUpCtrl'
}
}
})

.state('app.reservations', {
url: "/reservations",
cache: false,
views: {
'menuContent': {
templateUrl: "app/views/reservations.html",
controller: 'ReservationsCtrl'
}
}
})

.state('app.reservationdetail', {
url: "/reservations/:reservationid",
views: {
'menuContent': {
templateUrl: "app/views/reservationdetail.html",
controller: 'ReservationDetailCtrl'
}
}
})

.state('app.orders', {
url: "/orders",
cache: false,
views: {
'menuContent': {
templateUrl: "app/views/orders.html",
controller: 'OrdersCtrl'
}
}
})

.state('app.orderdetail', {
url: "/orders/:orderid",
views: {
'menuContent': {
templateUrl: "app/views/orderdetail.html",
controller: 'OrderDetailCtrl'
}
}
})

.state('app.loyaltyhistory', {
url: "/loyaltyhistory",
cache: false,
views: {
'menuContent': {
templateUrl: "app/views/loyaltyhistory.html",
controller: 'LoyaltyHistoryCtrl'
}
}
})

.state('app.notifications', {
url: "/notifications",
cache: false,
views: {
'menuContent': {
templateUrl: "app/views/notifications.html",
controller: 'NotificationsCtrl'
}
}
});



$urlRouterProvider.otherwise('/app/products');

});

var serviceUrl = ' http://localhost:6787/ ';

app.constant('ngAuthSettings', { apiServiceBaseUri:服务Url, clientId: 'ngAuthApp', 登录凭据:'登录凭据'});

这是我的服务

app.factory('loyaltyservice', ['$http', '$q', '$log', 'ngAuthSettings', function ($http, $q, $log, ngAuthSettings) {

var loyaltyFactory = {};
var webAPIbase = ngAuthSettings.apiServiceBaseUri;
var loginCredentailKey = ngAuthSettings.loginCredentail;

var getLoyaltyTransactionDetails = function (userId) {

var deferred = $q.defer();

$http({
method: 'GET',
url: webAPIbase + "api/Loyalty/GetLoyaltyTransactionDetails",
params: {
userId: userId
}
}).success(function (response) {

deferred.resolve(response);

}).error(function (err, status, header, config) {

deferred.reject(err);
});

return deferred.promise;

};

loyaltyFactory.getLoyaltyTransactionDetails = getLoyaltyTransactionDetails;

return loyaltyFactory;

}]);

非常感谢任何帮助。

最佳答案

对不起,大家。我忘记在防火墙中启用端口。启用后即可开始工作。

关于javascript - 设备模式下 Web API 调用失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29075515/

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