Guest User

Untitled

a guest
Jan 19th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. 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...
  2.  
  3. ## code from aspx.cs
  4.  
  5. public partial class login : System.Web.UI.Page
  6. {
  7. protected void Page_Load(object sender, EventArgs e)
  8. {
  9.  
  10. }
  11.  
  12. [WebMethod(EnableSession = true)]
  13. public static User VerifyLogin(string sEmail, string sPassword)
  14. {
  15.  
  16. TempusEntities context = new TempusEntities();
  17.  
  18. var query = context.Users.FirstOrDefault(u => u.Email == sEmail && u.Password == sPassword);
  19.  
  20. if (query != null)
  21. {
  22. HttpContext.Current.Session.Add("User", (User)query);
  23. return (User)query;
  24. }
  25. else
  26. return null;
  27.  
  28. }
  29. }
  30.  
  31. ## JavaScript from aspx page
  32.  
  33. <script type="text/javascript">
  34. $(document).ready(function () {
  35. // Add the page method call as an onclick handler for the div.
  36.  
  37.  
  38. $("#loginfailed").dialog({ autoOpen: false, modal: true, buttons: { "Ok": function () { $(this).dialog("close"); } } });
  39.  
  40.  
  41. });
  42.  
  43. $("#btnLogin").click(function () {
  44. var email = $('#txtEmail').text;
  45. var passwd = $('#txtPassword').text;
  46. $.ajax({
  47. type: "POST",
  48. url: "login.aspx/VerifyLogin",
  49. data: "{ sEmail:" + $('#txtEmail').text + "," + "sPassword: " + $('#txtPassword').text + "}",
  50. contentType: "application/json; charset=utf-8",
  51. dataType: "json",
  52. success: LoginSuccess,
  53. error: LoginFailed
  54. });
  55. });
  56. function LoginSuccess(data) {
  57. window.location('index.aspx?user=' + data.d.hasOwnProperty('UserId'));
  58. }
  59.  
  60. function LoginFailed() {
  61. $("#loginfailed").dialog('open');
  62.  
  63. }
Add Comment
Please, Sign In to add comment