Advertisement
Guest User

Untitled

a guest
Sep 26th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. $(function () {
  2.  
  3. $("#empbutton").click(function (e) {
  4. var lastname = $("#TextBoxLastname").val();
  5. $("#lblstatus").text("please wait...");
  6.  
  7. ajaxCall("Get", "api/employees/" + lastname, "").done(function (data) {
  8. if (data.Lastname !== "not found") {
  9. $("#email").text(data.Email);
  10. $("#title").text(data.Title);
  11. $("#firstname").text(data.Firstname);
  12. $("#phone").text(data.Phoneno);
  13. ajaxCall("Get", "api/departments/" + data.DepartmentID, "").done(function (data) {
  14. if (data.Name !== "not found") {
  15. $("#departmentname").text(data.Name);
  16. }
  17. else {
  18. $("departmentname").text("");
  19. }
  20.  
  21. }).fail(function (jqXHR, textStatus, errorThrown) {
  22. errorRoutine(jqXHR);
  23. });
  24. $("#lblstatus").text("employee found");
  25. }
  26. else {
  27. $("#firstname").text("not found");
  28. $("#email").text("");
  29. $("#title").text("");
  30. $("#phone").text("");
  31. $("#lblstatus").text("no such employee");
  32. }
  33. }).fail(function (jqXHR, textStatus, errorThrown) {
  34. errorRoutine(jqXHR);
  35. });//ajax call
  36. });//button click
  37.  
  38. });//jquery default function
  39.  
  40. function ajaxCall(type, url, data) {
  41. return $.ajax({//return the promise that `$.ajax` returns
  42. type: type,
  43. url: url,
  44. data: JSON.stringify(data),
  45. contentType: "application/json; charset=utf-8",
  46. dataType: "json",
  47. processData: true
  48. });
  49. }
  50.  
  51.  
  52. function errorRoutine(jqXHR) {//common error
  53. if (jqXHR.responseJson == null) {
  54. $("#lblstatus").text(jqXHR.responseText);
  55. }
  56. else {
  57. $("#lblstatus").text(jqXHR.responseJson.Message);
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement