I don't understand how the $http
service works. I have a controller that calls a factory and the factory calls a WS function.
If I run the app on debug mode, the factory calls the WS function and the WS function returned what I suppose is an json object.
On the other hand, when I watch in the web console, I get a message "undefined". What should return the WS function? Or what's wrong in my factory?
Thanks in advance.
This is the VB.Net Web Service function:
<ScriptMethod(ResponseFormat:=ResponseFormat.Json, XmlSerializeString:=False)> _
<WebMethod()> _
Public Function getLogin(ByVal email As String, ByVal password As String) As String
Dim dt As New Data.DataTable
Dim result As String = ""
Using con As New SqlConnection(sConn)
'Dim sql As String = "Select id_usuario, nombre_usuario id_tipo_usuario from binder_usuarios where email = @email and password = @password"
Dim sql As String = "Select * from binder_usuarios where email = @email and password = @password"
Dim cmd As New SqlCommand
cmd.CommandText = sql
cmd.Connection = con
cmd.Parameters.AddWithValue("@email", email)
cmd.Parameters.AddWithValue("@password", password)
Dim dataAdapter As New SqlDataAdapter(cmd)
dataAdapter.Fill(dt)
If dt.Rows.Count > 0 Then
result = JsonConvert.SerializeObject(dt, New JavaScriptDateTimeConverter())
Return result
Else
result = "e"
End If
Return result
End Using
End Function
the WS function return a string:
"[{"id_usuario":3,"nombre_usuario":"Quethzel","apellido_paterno":"Diaz","apellido_materno":"Zarate","id_area":1,"id_tipo_usuario":1,"password":"sa","email":"hqdiaz@lis.com.mx"}]"
this is the factory:
function fcQAuth($http, $q, $window) {
return {
loginAuth: function(credentials) {
$http.post('../ws/wsReact.asmx/getLogin', credentials)
.success(function(data, status) {
return "your data it's Ok, in da face !";
})
.error(function(data, status) {
return "don't give up Nigga";
});
//return "myUser. " + credentials.email + ", myPass." + credentials.password;
}
}
}; // end fcQAuth factory
And this is the controller, that call the factory:
function loginCtrl($scope, $q, $http, $location, fcQAuth) {
$scope.loginUser = function() {
var credentials = {
email: $scope.user.email === '' || $scope.user.email === undefined ? 0 : $scope.user.email,
password: $scope.user.password === '' || $scope.user.password === undefined ? 0 : $scope.user.password
};
$scope.userInfo = fcQAuth.loginAuth(credentials);
console.log($scope.userInfo);
};
};