Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I'm getting a SystemArgument.Exception when I try to pass the parameters to the WebMethod, which is part of the data: option of the jQuery .ajax call...
- ## code from aspx.cs
- public partial class login : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- [WebMethod(EnableSession = true)]
- public static User VerifyLogin(string sEmail, string sPassword)
- {
- TempusEntities context = new TempusEntities();
- var query = context.Users.FirstOrDefault(u => u.Email == sEmail && u.Password == sPassword);
- if (query != null)
- {
- HttpContext.Current.Session.Add("User", (User)query);
- return (User)query;
- }
- else
- return null;
- }
- }
- ## JavaScript from aspx page
- <script type="text/javascript">
- $(document).ready(function () {
- // Add the page method call as an onclick handler for the div.
- $("#loginfailed").dialog({ autoOpen: false, modal: true, buttons: { "Ok": function () { $(this).dialog("close"); } } });
- });
- $("#btnLogin").click(function () {
- var email = $('#txtEmail').text;
- var passwd = $('#txtPassword').text;
- $.ajax({
- type: "POST",
- url: "login.aspx/VerifyLogin",
- data: "{ sEmail:" + $('#txtEmail').text + "," + "sPassword: " + $('#txtPassword').text + "}",
- contentType: "application/json; charset=utf-8",
- dataType: "json",
- success: LoginSuccess,
- error: LoginFailed
- });
- });
- function LoginSuccess(data) {
- window.location('index.aspx?user=' + data.d.hasOwnProperty('UserId'));
- }
- function LoginFailed() {
- $("#loginfailed").dialog('open');
- }
Add Comment
Please, Sign In to add comment