我希望从serice页面到php页面有多重价值。我想传递数据',' albimg',' albvideo'到php page.now我发现错误,如图所示。
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')";
答案 0 :(得分:1)
你可以使用param属性:像这样;
var data = {"data":data,"albimg":albimg,"albvideo":albvideo};
$http({ url: "js/data/album.php", method: "POST", params: data })
答案 1 :(得分:1)
看看这个例子:
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;
}
}
我认为您忘了在函数中添加$defer
。你真的需要异步吗? Beacouse如果您使用$q
它需要它。但是如果你只想将数据发送到php文件最简单的方法来使用这样的东西:
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;
};
}]);
答案 2 :(得分:1)
成功回调中没有定义动作参数。
您的代码
private void nextpageintent(String photoUri){
Bundle bundle = new Bundle();
bundle.putString("photo", photoUri);
picture picture = new picture();
picture .setArguments(bundle);
}
应该是
.success(function (data, status, headers, config) // No Action here
{
console.log(status + ' - ' + action); // This line gives error
deferred.resolve(action);
})