请求$ http.jsonp获取ANgularJS

时间:2017-06-28 04:04:45

标签: angularjs web-services jsonp angular-services

我正在尝试理解并在项目中进行一些小修改。它在AngularJS jsonp注册表单上。以前表单有名字,姓氏......就像许多输入一样。但我希望用户输入电子邮件,pw并仅确认密码。然后我从html文件中删除了不需要的输入字段并尝试注册。但我的注册无效。如果成功完全响应(已注册:1)我的功能应重定向到个人资料页面。

Reg.html

<form ng-submit="signUp()">
  <div class="input-group">
    <input id="email" type="email" ng-model="user.email" required class="form-control" name="email">
 </div>
 <div class="input-group">
    <input type="password" ng-model="user.pwd" required class="form-control" >
 </div>
 <div class="input-group last-child">
              <input type="password" ng-model="user.cpwd" required class="form-control" >
 </div>
 <button class="btn" type="submit">Sign Up</button>
</form>

Login.js控制器

myApp.controller('LoginController', function ($scope, $rootScope, $location, $http, $window,  Common, localStorageService, SweetAlert) {

$scope.user = {
    user_id : "",
    first_name : "",
    last_name : "",
    dob : "",
    mobile : "",
    gender : "",
    email : "",
    pwd : "",
    profile_img : ""
  };

$scope.signUp = function () {


    Common.get('mobile/update_profile', $scope.user, function (res, err) {
      //$window.alert(" "+jSON.stringify(res));
      if (res.user_id > 0) {

          localStorageService.set("user", res);
          $rootScope.$emit('profileChanged', function () {
          $window.location.href = '#/' + profile;
          $window.location.reload();
        });
      } else {
        SweetAlert.error("Sign Up request failed, please check the details and try again.", {
          title : "Sign Up Failed!",
          confirmButtonColor : '#e74c3c'
        });
      }
    }, true);
  };
});

Common.js

myApp.factory('Common', function ($http,$window) {

return {
    get : function (url, data, callback) {

      try {

        var req = {};
        req.jsonpCallbackParam = 'callback';
        req.params = data;
        $http.jsonp(window.API_URL + url, req).then(function (response) {
          if (response.data) {
           callback(response.data, {});
           $window.alert("mail "+JSON.stringify(response.data));
          } else {
            callback({}, "Some Error Occured");

          }
        });

      } catch (err) {
        callback({}, err.message);

      }
    }

});

postman client api和common.js alert return below response

enter image description here

Chrome console错误消息

enter image description here

0 个答案:

没有答案