我尝试在iphone上测试离子应用,但服务器端不接受来自iphone(离子)的后期数据。 我不明白如何解决这个问题。我需要你的帮助。
错误消息如下。
[Error] Failed to load resource: Could not connect to the server. (login, line 0) http://localhost:1337/user/login
[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (register-device-token, line 0) https://push.ionic.io/api/v1/register-device-token
这是service.js的离子代码
factory('AuthenticationService', ['$http', '$q', 'localStorageService', function($http, $q, localStorageService){
function loginUser(post){
var deferred = $q.defer();
$http.post('http://localhost:1337/user/login', post)
.success(function (data) {
if (data.error || !data.user) {
deferred.reject(data.error);
}
localStorageService.set('user', data.user);
user = data.user;
deferred.resolve(data.user);
})
.error(function () {
deferred.reject('error');
});
return deferred.promise;
}
return {
login: loginUser
};
}])
和controller.js在这里。
// inside of controller.js
AuthenticationService.login(user).then(function (result){
$ionicLoading.hide();
$state.go('app.profile');
}, function (error) {
$ionicLoading.hide();
console.log('error', error);
});
↓ sails.js的路线
module.exports.routes = {
......
'POST /user/login': {
controller: 'LoginController',
action: 'create',
cors: true
},
......
}
sails.js的LoginController.js
create: function(req, res) {
'use strict';
sails.log.debug('create user method in');
var user = req.params,
uuid = NodeUuid.v4();
sails.log.debug('user = ' + JSON.stringify(user));
// Validator.validateUserInfo(user);
User.create({
//画面からの入力情報
}).exec(function (err, user) {
if (err) {
if (err.code == 11000) {
StatusService.returnResponse(res, Constants.statusCode.BadRequest, err, Constants.message.error.alreadyExistsEmail);
}
} else {
StatusService.returnResponse(res, Constants.statusCode.OK, null, '');
}
});
},
答案 0 :(得分:4)
替换为:http://localhost:1337/user/login
使用PC的本地IP地址(您可以通过在cmd中键入ipconfig找到您的IP地址)
http://yourIP:1337/user/login
还要确保您的电脑和移动设备连接到同一个wifi。