【发布时间】:2015-08-28 01:40:43
【问题描述】:
我有一个表单,我通过发布请求将其数据提交给服务器。这是我在控制器中的请求代码:
$scope.submitFormData = function (obj, html) {
var posOptions = {timeout: 10000, enableHighAccuracy: false};
$cordovaGeolocation
.getCurrentPosition(posOptions)
.then(function (position) {
var lat = position.coords.latitude;
var long = position.coords.longitude;
var formId = html.Id;
var url = base_url+"put/putFormFilledRawData.php?userid="+window.localStorage.userid+"&token="+window.localStorage.token+"&formid="+formId+"&lat="+lat+"&long="+long;
var data = $(obj.target).serialize();
$http.post(url, data).
success(function(data, status, headers, config) {
if(data.alert == 'SUCCESS'){
var myPopup = $ionicPopup.show({
title: 'Confirmation',
subTitle: 'Your data has been submitted successfully',
scope: $scope,
buttons: [
{
text: '<b>Ok</b>',
type: 'button-calm',
onTap: function(e) {
$(this).hide();
}
},
]
});
}
}).
error(function(data, status, headers, config) {
var myPopup = $ionicPopup.show({
title: 'Error',
subTitle: 'An error has been occured try again later!',
scope: $scope,
buttons: [
{
text: '<b>Ok</b>',
type: 'button-calm',
onTap: function(e) {
$(this).hide();
}
},
]
});
});
}, function (err) {
var myPopup = $ionicPopup.show({
title: 'Location Error',
subTitle: 'Not able to get the current location!!!',
scope: $scope,
buttons: [
{
text: '<b>Ok</b>',
type: 'button-calm',
onTap: function(e) {
$(this).hide();
}
},
]
});
});
}
})
当我在我的网络浏览器上运行它并提交表单数据时,日期会以 lat 和 long 形式提交,并且我会收到一个带有 SUCCESS 警报的响应。但是,当我构建应用程序并在我的 Android 手机上尝试它时,请求不会提交,而是执行错误分支并在弹出窗口中向我显示一条自定义消息 An error has been occurred try again later! 所以请求没有从移动设备提交。
我正在构建的应用程序使用带有 Ionic 框架和 AngularJS 的 Cordova。
【问题讨论】:
-
找出错误回调的数据和状态参数包含什么。
-
是的,作为@JBNizet,尝试显示这些论文
data, status, headers, config,然后更新您的帖子;)
标签: angularjs cordova ionic-framework ionic