0

I want to multiple value from from serice page to php page.I want to pass 'data','albimg','albvideo' to php page.now I caught the error as shown in image. enter image description here

var deferred = $q.defer();
            data.pagename = "create_album";
            $http.post('js/data/album.php', {action:{"data":data,"albimg":albimg,"albvideo":albvideo}})
                    .success(function (data, status, headers, config)
                    {
                        console.log(status + ' - ' + action);
                        deferred.resolve(action);
                    })
                    .error(function (action, status, headers, config)
                    {
                        deferred.reject(action);
                        console.log('error');
                    });

            return deferred.promise;
php page:
$postdata = file_get_contents("php://input",true);
$request = json_decode($postdata);
$now = date('Y-m-d H:i:s');
echo $sql="INSERT INTO `$prefix.album` (CONTENT_VALUES,CreatedTime)VALUES('$postdata','$now')";
1
  • 1
    action is not defined. Above code, action is not a variable, ( is a property ) Commented Nov 23, 2015 at 4:57

3 Answers 3

1

you can do it by using param property: like this;

var data = {"data":data,"albimg":albimg,"albvideo":albvideo};

$http({ url: "js/data/album.php",    method: "POST",    params: data    })
Sign up to request clarification or add additional context in comments.

Comments

1

There is no action param defined in success callback.

Your code

.success(function (data, status, headers, config) // No Action here
    {
        console.log(status + ' - ' + action); // This line gives error
        deferred.resolve(action);
    })

Should be

.success(function (data, status, headers, config, action) // Add Action here
        {
            console.log(status + ' - ' + action);
            deferred.resolve(action);
        })

Comments

1

Look to this example:

 function PhoneListCtrl($scope, phones) {
      $scope.phones = phones;
      $scope.orderProp = 'age';
    }

    PhoneListCtrl.resolve = {
      phones: function(Phone, $q) {
        var deferred = $q.defer();



 deferred.reject();
    Phone.query(function(successData) {
            deferred.resolve(successData); 
    }, function(errorData) {
            deferred.reject();
    });
    return deferred.promise;
  },
  delay: function($q, $defer) {
    var delay = $q.defer();
    $defer(delay.resolve, 1000);
    return delay.promise;
  }
}

I think that you forget add $defer to your function. Do you realy need asynchronously? Beacouse if you use $q it's that you need it. But if you just want to send data to php file easiest way to use something like this:

angular.module('httpExample', [])
.controller('FetchController', ['$scope', '$http', '$templateCache',
  function($scope, $http, $templateCache) {
    $scope.method = 'Post';
    $scope.url = 'http-hello.php';

    $scope.fetch = function() {
      $scope.code = null;
      $scope.response = null;

      $http({method: $scope.method, url: $scope.url, cache: $templateCache}).
        then(function(response) {
          $scope.status = response.status;
          $scope.data = response.data;
        }, function(response) {
          $scope.data = response.data || "Request failed";
          $scope.status = response.status;
      });
    };

    $scope.updateModel = function(method, url) {
      $scope.method = method;
      $scope.url = url;
    };
  }]);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.