Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 10th, 2012  |  syntax: None  |  size: 0.93 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. jQuery ajax POST to ASP.NET WebMatrix action
  2. $.ajax({
  3.    url: '/File/Location',
  4.    type: 'POST',
  5.    data: 'username=email@you.com&password=secret',
  6.    success: function (data){
  7.     console.log(data);
  8.    },
  9.    error: function (xhr, status, error){
  10.     console.warn(error);
  11.    }
  12.  });
  13.        
  14. Request = @Request.Form
  15.  
  16. if(IsPost){
  17.  //Aunthentication logic
  18. }
  19.        
  20. var password = Request["password"];
  21. var username = Request["username"];
  22. if(IsPost){
  23.     //Do your thing
  24. }
  25.        
  26. var password = Request.Form["password"];
  27.        
  28. public class UserFormInformation{
  29.     public string Username{ get; set; }
  30.     public string Password { get; set; }
  31. }
  32.  
  33. [HttpPost]
  34. public ActionResult Login(UserFormInformation info)
  35. {
  36.     //...
  37. }
  38.  
  39.  
  40.  
  41. $.ajax({
  42.    url: '/File/Location/Login',
  43.    type: 'POST',
  44.    data: 'username=email@you.com&password=secret',
  45.    success: function (data){
  46.     console.log(data);
  47.    },
  48.    error: function (xhr, status, error){
  49.     console.warn(error);
  50.    }
  51.  });