87,997
社区成员




<script type="text/javascript">
(function (window) {
angular.module('myApp', [])
.controller('myController', ['$scope', '$http', function ($scope, $http) {
var url = "../handler/LoginHandler.ashx";
$scope.queryUser = function () {
$scope.username = angular.element('#txtUsername').val();
$scope.factory = angular.element('#txtFactory').val();
console.log($scope.username + $scope.factory); //可以获取到值
$http.post(url,
{ params: { username: $scope.username, factory: $scope.factory } }
).success(function (response) {
$scope.users = response;
});
}
}]);
})(window);
</script>
后台代码
string username = context.Request["username"] ?? ""; //截获断点查看 context.Request["username"] 值为null
string factory = context.Request["factory"] ?? "";
还是不行啊,问题到底出在哪?
//这个是标准的格式
$http.post(url, {params: {xx:xx}}).success(function(response){
});
$http.post("/SpecialActivity/SetXml",
{
xml: JSON.stringify(data)
}).success(function (custs) {
if (custs.toLowerCase() === "true")
alert('保存成功!');
else
alert("失败!文件未保存");
}).error(function (error) {
alert(error.message);
});
<div ng-controller="myController">
用户名:<input type="text" id="txtUsername" value="{{username}}"/>
工厂:<input type="text" id="txtFactory" value="{{factory}}" />
<input type="button" value="查询" ng-click="queryUser()"/>
<table>
<tr><th>用户ID</th><th>角色ID</th><th>口令</th><th>工厂</th><th>创建者</th></tr>
<tr ng-repeat="user in users">
<td>{{ user.USERID }}</td>
<td>{{ user.ROLEID }}</td>
<td>{{ user.PASSWORD }}</td>
<td>{{ user.FACTORYID }}</td>
<td>{{ user.MASTER }}</td>
</tr>
</table>
</div>
这是js代码
(function (window) {
angular.module('myApp', [])
.controller('myController', ['$scope', '$http', function ($scope, $http) {
var url = "../handler/LoginHandler.ashx";
$scope.queryUser = function () {
$scope.username = angular.element('#txtUsername').val();
$scope.factory = angular.element('#txtFactory').val();
console.log($scope.username +$scope.factory);
//console.log是有值的
}
$http.post(url).success(function (response) {
$scope.users = response;
});
}]);
})(window);
这是后台处理代码
//这里取不到值
string username = context.Request["username"] ?? "";
string factory = context.Request["factory"] ?? "";
$http.post(url,
{ username: $scope.username, factory: $scope.factory }
).success(function (response) {
$scope.users = response;
});