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.
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')";
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 })
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;
};
}]);
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);
})