通过休息服务数据成功插入数据库但获得$ http状态0:离子

时间:2016-04-25 08:42:46

标签: angularjs ionic-framework

我在离子休息服务方面遇到问题。 我叫离子休息服务。我的服务被调用,数据被插入数据库..但在离子后,我得到状态0。 我怎么解决这个问题?作为响应服务我设置状态201 .. 如果我通过休息客户端调用此服务,则获得201

但是在离子中我得到了0

以下是我的控制器

    angular.module('starter.services', [])

.factory('RegService', function($http,$q) {
return{
  insertRegistration: function (reg) {
            var config = {
                headers : {
                    'Content-Type': 'application/json;'
                }
            }



       $http.post("http://XXX:8080/XXX/add/", reg)

             //SUCCESS: this callback will be called asynchronously when the response is available
      .then(function (response) {
        console.log("Successful: response from submitting data to server was: " + response);
        alert("succ");
               $q.defer().resolve({
                 data: response //RETURNING RESPONSE SINCE `DATA` IS NOT DEFINED
               });
             },

             //ERROR:  called asynchronously if an error occurs or server returns response with an error status.
             function (response) {
               console.log("Error: response from submitting data to server was: " + response);
                  alert("error " + JSON.stringify(response));

               //USING THE PROMISE REJECT FUNC TO CATCH ERRORS
               $q.defer().reject({
                 data: response //RETURNING RESPONSE SINCE `DATA` IS NOT DEFINED
               });

             }
           );
      return $q.defer().promise;
    }
}})

它出错了部分......但是我检查了DB数据插入.. 我怎么解决这个问题? 我必须为成功状态做些什么改变?

0 个答案:

没有答案