Advertisement
Guest User

Untitled

a guest
Sep 18th, 2014
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. <div style="width:600px; margin-left:auto; margin-right:auto">
  2. <div style="background-color: lightgray">
  3. <h2>My Products</h2>
  4. </div>
  5. <p>Click the button to Get Products with an Ajax call</p>
  6.  
  7. <input id="btnAjax" name="btnAjax" type="button" value="Get Products" />
  8. <div id="products" style="background-color:lightskyblue">
  9. <div id='loadingmessage' style='display:none'>
  10. loading...
  11. </div>
  12. </div>
  13. </div>
  14.  
  15. @section Scripts {
  16. @*@Scripts.Render("~/bundles/jqueryval")*@
  17. <script>
  18. $('#btnAjax').click(function () {
  19. $.ajax({
  20. url: '/Test/GetProducts',
  21. contentType: 'application/html; charset=utf-8',
  22. data: { id: 1 },
  23. type: 'GET',
  24. dataType: 'html'
  25. })
  26. .success(function (result) {
  27. $('#products').html(result);
  28. $('#loadingmessage').hide();
  29. })
  30. .error(function (xhr, status, throwError) {
  31. alert(status);
  32. })
  33. });
  34. </script>
  35. }
  36.  
  37. public PartialViewResult GetProducts(int id)
  38. {
  39. var listOfCourses = db.Courses.ToList();
  40. Task.Delay(9000000);
  41. if(id == 1)
  42. throw new Exception("something bad");
  43.  
  44. return PartialView("_GetProducts", listOfCourses);
  45. }
  46.  
  47. <input id="btnAjax" name="btnAjax" type="button" value="Get Products" data:id="1" />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement