Javascript 可以在Angular JS中的HTTP post请求中传递多个$scope变量吗?
这里我传递的是Javascript 可以在Angular JS中的HTTP post请求中传递多个$scope变量吗?,javascript,angularjs,Javascript,Angularjs,这里我传递的是$scope.query,$scope.algoName。这在AngularJS中可能吗 您可以将它们作为数据参数传入,$http.post()接受: $scope.getQuery = function() { var response = $http.post('/test/getQuery', $scope.query, $scope.algoName); response.success(function(data, status, headers,
$scope.query
,$scope.algoName
。这在AngularJS中可能吗 您可以将它们作为数据
参数传入,$http.post()
接受:
$scope.getQuery = function() {
var response = $http.post('/test/getQuery', $scope.query, $scope.algoName);
response.success(function(data, status, headers, config) {
console.log($scope.query);
console.log($scope.algoName);
});
}
然后这些将作为请求消息数据发送。您可以将它们作为
数据
参数传入,$http.post()
接受:
$scope.getQuery = function() {
var response = $http.post('/test/getQuery', $scope.query, $scope.algoName);
response.success(function(data, status, headers, config) {
console.log($scope.query);
console.log($scope.algoName);
});
}
然后,这些将作为请求消息数据发送。您需要此要求的原因是什么?通常要求在发送之前构建数据响应对象
var data = {
query: $scope.query,
algoName: $scope.algoName
};
$scope.getQuery = function() {
var response = $http.post('/test/getQuery', data);
response.success(function(data, status, headers, config) {
console.log($scope.query);
console.log($scope.algoName);
});
};
您需要此要求的原因是什么?通常要求在发送之前构建数据响应对象
var data = {
query: $scope.query,
algoName: $scope.algoName
};
$scope.getQuery = function() {
var response = $http.post('/test/getQuery', data);
response.success(function(data, status, headers, config) {
console.log($scope.query);
console.log($scope.algoName);
});
};
Angular最多可接受3个参数
从
post(url、数据、[config])
数据可以是您想要传递到url的任何内容,您基本上可以这样做:
var data = {}
data.query = $scope.query;
data.algoName = $scope.algoName;
var response = $http.post('/test/getQuery', data);
另一种方法是将它保存在变量中,然后解析它。我更喜欢使用第一种方法,但是如果你想传递它,那是另一种方法
$scope.getQuery = function() {
// your endpoint
var endpoint = '/test/getQuery';
// data you want to sent the server
var data = {
query: $scope.query,
algoName: $scope.algoName
};
// all your configs
var config = {
headers: {
'Content-Type': 'application/json' // or whatever you need here
}
};
// This makes the call, the .then deals with the promise
// the first function is success and the second deals with fail
$http.post(endpoint, data, config).then(function(response) {
console.debug(response);
}, function (error) {
console.debug(error);
});
};
请记住,$hhtp
返回一个承诺,。然后
就是如何解析它,并提取延迟信息的方法。Angular的最多可接受3个参数
var response = $http.post(endpoint, data, config);
response.then(function(response) {
console.debug(response);
}, function (error) {
console.debug(error);
});
从
post(url、数据、[config])
数据可以是您想要传递到url的任何内容,您基本上可以这样做:
var data = {}
data.query = $scope.query;
data.algoName = $scope.algoName;
var response = $http.post('/test/getQuery', data);
另一种方法是将它保存在变量中,然后解析它。我更喜欢使用第一种方法,但是如果你想传递它,那是另一种方法
$scope.getQuery = function() {
// your endpoint
var endpoint = '/test/getQuery';
// data you want to sent the server
var data = {
query: $scope.query,
algoName: $scope.algoName
};
// all your configs
var config = {
headers: {
'Content-Type': 'application/json' // or whatever you need here
}
};
// This makes the call, the .then deals with the promise
// the first function is success and the second deals with fail
$http.post(endpoint, data, config).then(function(response) {
console.debug(response);
}, function (error) {
console.debug(error);
});
};
请记住,$hhtp
返回一个承诺,。然后
就是如何解决它并提取延迟信息的
var response = $http.post(endpoint, data, config);
response.then(function(response) {
console.debug(response);
}, function (error) {
console.debug(error);
});
您的数据变量需要在函数中。。。可能是他在直接调用函数
您的数据变量需要在函数中。。。可能他正在直接调用一个函数……您想要完成的是什么?您想要完成的是什么?