0
我想使web服務,通過角度的Javascript $ http.post 需要表單數據並插入到EMPLOYEE表,但我上了督察Asp.net ASMX Web服務
「後此錯誤。 ........內部服務器錯誤500" 的幫助,請這是代碼
<!doctype html>
<html ng-app="app">
<head>
<title>testgrid</title>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular-touch.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular-animate.js"></script>
<script src="http://ui-grid.info/docs/grunt-scripts/csv.js"></script>
<script src="http://ui-grid.info/docs/grunt-scripts/pdfmake.js"></script>
<script src="http://ui-grid.info/docs/grunt-scripts/vfs_fonts.js"></script>
<script src="http://ui-grid.info/release/ui-grid.js"></script>
<link rel="stylesheet" href="http://ui-grid.info/release/ui-grid.css" type="text/css">
<link rel="stylesheet" href="main.css" type="text/css">
</head>
<body>
<div ng-app="app" ng-controller="myctrl">
<form>
<input name="firstname"/>
<input name="firstname" type="text" ng-model="firstname" /><br/>
<input name="lastname" type="text" ng-model="lastname" /><br/>
<input name="middlename" type="text" ng-model="middlename"/><br />
<input name="addrss" type="text" ng-model="address" /><br />
<input name="email" type="text" ng-model="email" /><br />
<input name="salary" type="text" ng-model="salary" /><br />
<input type="button" value="submit" ng-click="insertdata()"/><br />
</form>
</div>
<script>
var app = angular.module('app', [])
var config = { headers: { "Content-Type": "application/json" } };
app.controller('myctrl', function ($scope, $http) {
$scope.insertdata = function() {
$http.post("insertemployee.asmx/setemployeeData", { 'firstname': $scope.firstname, 'lastname': $scope.lastname, 'middlename': $scope.middlename, 'address': $scope.address, 'email': $scope.email, 'salary': $scope.salary })
.success(function (data, status, headers, config) { console.log("Data inserted successfully");})
}
})
</script>
</body>
</html>
[WebMethod]
public void getEmployeeData()
{
List <Employee>employeelist= new List<Employee>();
string cs = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using(SqlConnection con=new SqlConnection(cs))
{
SqlCommand cmd = new SqlCommand("SELECT * FROM Employee",con);
con.Open();
SqlDataReader rdr=cmd.ExecuteReader();
while (rdr.Read())
{
Employee employee = new Employee();
employee.FirstName = rdr["FirstName"].ToString();
employee.LastName = rdr["LastName"].ToString();
employee.Salary = Convert.ToInt32(rdr["salary"]);
employeelist.Add(employee);
}
}
JavaScriptSerializer js = new JavaScriptSerializer();
Context.Response.Write(js.Serialize(employeelist));
}
}
}