0
我试图从我的离子应用程序发布数据到服务器。要使用的URL位于一个变量中。这里是我的尝试:使用AngularJS(离子框架)将数据POST到服务器
首先我创建了一个服务是这样的:
.service('PostTuto', ['$http',function($http) {
this.servicioPostTuto = function(tema,ubicacion,horario,nom_coe) {
return $http({
method: 'POST',
url: 'http://"""""".""".""""."""":8080/smartlandiotv2/webresources/entidades.datos/insert?apikey=3bff8615827f32442199fdb2ed4df4&trama={"Nombre":"'+tema+'","Apellido":"'+ubicacion+'","Sexo":"'+horario+'","Residencia":"'+nom_coe+'"}',
});
};
}])
在这个部分我在URL发送变量
tema
,
ubicacion
,
horario
,
nom_coe
和我的控制器
。我已经做到了这一点:
$scope.data = {};
$scope.create=function(){
$scope.nom_coe="IDfromSubject"
PostTuto.servicioPostTuto($scope.data.tema,$scope.data.ubicacion,$scope.data.horario,$scope.nom_coe)
.success(function(data){
var alertPopup = $ionicPopup.alert({
title: 'created'
});
})
.error(function(data){
var alertPopup = $ionicPopup.alert({
title: 'Error to post data'
});
});
};
//FIN POSTEAR DATOS A SERVIDOR
在这一部分,我收到我的html文件,从输入的数据。
<label class="item item-input item-stacked-label">
<span class="input-label"><strong>Tema:</strong></span>
<input type="text" ng-model="data.tema" ng-disabled="editar">
</label>
<label class="item item-input item-stacked-label">
<span class="input-label"><strong>Ubicacion:</strong></span>
<input type="text" ng-model="data.ubicacion" ng-disabled="editar">
</label>
<label class="item item-input item-stacked-label">
<span class="input-label"><strong>Horario:</strong></span>
<input type="text" ng-model="data.horario" ng-disabled="editar">
</label>
<a class="button button-block icon-left ion-ios-compose button-positive"
ng-disabled="!data.tema || !data.ubicacion || !data.horario" ng-click="create()">
create
</a>
当我尝试发布的数据,我的应用程序返回我一个错误“错误发布数据”,我该怎么解决呢?
你可以检查你的webservice邮递员它是否工作。 –