Click here to Skip to main content
15,898,933 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have table Called Mst_User for Login Checkup. The Column are Us_No, Us_Name, Us_Password and Us_Admin.

I have created OData Services. Now i want to check the login User name & password.

OData Services work perfectly. I checked through explore.

Below is the code, Please tell me how to check this in ajax.
JavaScript
var _url = "http://localhost:58890/DataService.svc/Mst_User?$filter=Us_Name eq '" + LoginPage.currentUser.UserName() + "' and Us_Password eq'" + LoginPage.currentUser.Password() + "'&$format=json";
    $.ajax({
        type: "GET",
        url: _url,
        timeout: 10000,
        async: true,
        dataType: "json",
        contentType: "application/jsonp; charset=utf-8",
        success: function (data) {
//How to check here if Us_Admin=1 then Navigate
//Else
//Show error
        }
    });

Thanks
Basit
Posted
v2

1 solution

May be like...
JavaScript
if(data.Us_Admin == 1)
{
    window.location.href = "home.html";
}
else
{
    alert("Error");
}
 
Share this answer
 
Comments
basitsar 12-Jul-15 1:58am    
showing login failed!
Hey, you need to check the server side code and check what exactly you are returning for Us_Admin. Debug and see.
basitsar 12-Jul-15 2:44am    
The Us_Admin is a numeric field, if Us_admin=1 then redirect to another page. I checked in the database its showing also 1, But the code what you suggested is not working with that code showing login failed.

Thanks
Basit
As I said, you need to check the service method Mst_User, what exactly you are returning and how. Debug that. Also debug in the success method.
basitsar 12-Jul-15 3:04am    
Below is the o/p of webservices

{"d":[{"__metadata":{"id":"http://localhost:58890/DataService.svc/Mst_User(1)","uri":"http://localhost:58890/DataService.svc/Mst_User(1)","type":"CMModel.Mst_User"},"Trn_CallLog":{"__deferred":{"uri":"http://localhost:58890/DataService.svc/Mst_User(1)/Trn_CallLog"}},"Us_No":1,"Us_Name":"Basit","Us_Password":"s","Us_Admin":1,"Us_Customer":1,"Us_CallAssign":1,"Us_CreateCall":1}]}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900