code_junkie

ASP.NET MVC scenario, similar to 'Post your answer' on StackOverflow

Nov 14th, 2011
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. { "people": [
  2. { "firstName": "Brett", "lastName":"McLaughlin", "email": "brett@newInstance.com" },
  3. { "firstName": "Jason", "lastName":"Hunter", "email": "jason@servlets.com" },
  4. { "firstName": "Elliotte", "lastName":"Harold", "email": "elharo@macfaq.com" }
  5. ]}
  6.  
  7. <people>
  8. <person>
  9. <firstName>Brett</firstName>
  10. <lastName>McLaughlin</lastName>
  11. <email>brett@newInstance.com</email >
  12. </person>
  13. <person>
  14. <firstName>Jason</firstName>
  15. <lastName>Hunter</lastName>
  16. <email>jason@servlets.com</email >
  17. </person>
  18. <person>
  19. <firstName>Elliotte</firstName>
  20. <lastName>Harold</lastName>
  21. <email>elharo@macfaq.com</email >
  22. </person>
  23. </people >
  24.  
  25. public ContentResult ProcessRequestAction(string Email, string Password)
  26. {
  27. Product product = new Product();
  28. product.Name = "Apple";
  29. product.Expiry = new DateTime(2008, 12, 28);
  30. product.Price = 3.99M;
  31. product.Sizes = new string[] { "Small", "Medium", "Large" };
  32. return Content(JavaScriptConvert.SerializeObject(product));
  33. }
  34.  
  35. $.ajax({
  36. type: "POST", /* GET OR POST */
  37. url: "JSON_MVC_URL_HERE", /* your url here */
  38. dataType: "json", /* json or xml */
  39. data: null, /* JSON CODE HERE TO SET GET OR POST BACK PARAMS */
  40. success: function(data){
  41. alert(data.Name); /* Gets Name Element */
  42. alert(data.Expiry); /* Gets Expiry Element */
  43. alert(data.Price); /* Gets Price Element */
  44. jQuery.each(data.Sizes, function() { /* Get Each Size */
  45. alert(this);
  46. });
  47. }
  48. });
Add Comment
Please, Sign In to add comment