Guest User

Untitled

a guest
Jun 25th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. $j.ajax({
  2. type: "POST",
  3. url: "/Services/Cart.asmx/UpdateQuantity",
  4. data: data,
  5. contentType: "application/json; charset=utf-8",
  6. dataType: "json",
  7. success: function(msg) {
  8. var d = msg.d;
  9.  
  10. // etc.
  11. },
  12. error: function(xhr, msg) {
  13. var response = JSON.parse(xhr.responseText);
  14. var cart = $j('#cart');
  15. if (response.Message) {
  16. cart.before(' <div class="error">' + response.Message + '</div> ');
  17. }
  18. else {
  19. cart.before(' <div class="error">An unexpected error occurred.</div> ');
  20. }
  21. },
  22. complete: function(request, settings) {
  23. // Some other stuff.
  24. }
  25.  
  26. }); // end ajax
  27. alert('Initially thought this would be called after above .ajax call complete. But it is not. Rather, it is called before success etc.')
  28.  
  29. $j.ajax({
  30. type: "POST",
  31. url: "/Services/Cart.asmx/UpdateQuantity",
  32. data: data,
  33. contentType: "application/json; charset=utf-8",
  34. dataType: "json",
  35. success: newSuccessFunction(xhr,msg),
  36. error: function(xhr, msg) {
  37. var response = JSON.parse(xhr.responseText);
  38. var cart = $j('#cart');
  39. if (response.Message) {
  40. cart.before(' <div class="error">' + response.Message + '</div> ');
  41. }
  42. else {
  43. cart.before(' <div class="error">An unexpected error occurred.</div> ');
  44. }
  45. },
  46. complete: function(request, settings) {
  47. // Some other stuff.
  48. }
  49.  
  50. }); // end ajax
  51.  
  52. function newSuccessFunction(xhr,msg) {
  53. var d = msg.d;
  54. //... etc.
  55. $.ajax({ //...
  56. });
  57. alert('Initially thought this would be called after above .ajax call complete. But it is not. Rather, it is called before success etc.')
  58. }
Add Comment
Please, Sign In to add comment