The strain on the When method of jquery

Source: Internet
Author: User

Requirement: A, b two tasks are processed (whether a, B is successful or failed), and the following tasks are performed.
Code Listing 1:

Java code
  1. var leftresult = Leftpromise.then (
  2. function (value) {
  3. Console.info ("Jsona End");
  4. }, function () {
  5. Console.info ("Jsona fail");
  6. }
  7. );
  8. var rightresult = Rightpromise.then (
  9. function (value) {
  10. Console.info ("jsonb End");
  11. }, function () {
  12. $ ("#jsonB"). Val ("");
  13. Console.info ("jsonb fail");
  14. }
  15. );
  16. $.when (Leftresult, Rightresult). Always (
  17. function () {
  18. Console.info ("Start compare");
  19. });


You may be able to perform the following tasks directly after the a task fails.
The When method is defined as any failure, or all success is executed down. What do we do?
Through a always-on packaging solution:

Java code
  1. var leftresult = Leftpromise.then (
  2. function (value) {
  3. Console.info ("Jsona End");
  4. }, function () {
  5. Console.info ("Jsona fail");
  6. }
  7. ). Always (
  8. function () {
  9. Console.info ("Jsona always");
  10. var d = $. Deferred ();
  11. D.resolve ();
  12. return d.promise ();
  13. }
  14. );
  15. var rightresult = Rightpromise.then (
  16. function (value) {
  17. Console.info ("jsonb End");
  18. }, function () {
  19. $ ("#jsonB"). Val ("");
  20. Console.info ("jsonb fail");
  21. }
  22. ). Always (
  23. function () {
  24. Console.info ("jsonb always");
  25. var d = $. Deferred ();
  26. D.resolve ();
  27. return d.promise ();
  28. }
  29. );
  30. $.when (Leftresult, Rightresult). Always (
  31. function () {
  32. Console.info ("Start compare");
  33. });


The point here is that after then there is a Always,always method that returns must be successful, allowing the When method to satisfy the conditions that are successfully executed down.

_-html Tutorial-html Tutorial

A brief introduction to _-html tutorial-html of the Perak Ape tutorial

The _-html tutorial-html basics of the Perak Ape tutorial

Break Ape Tutorial _-html tutorial-html elements

Perak Ape Tutorial _-html Tutorial-html Properties

Break Ape Tutorial _-html tutorial-html Title

Break Ape Tutorial _-html Tutorial-html Paragraph

Break Ape Tutorial _-html Tutorial-html Links

Break Ape Tutorial _-html tutorial-html Head

Perak Ape Tutorial _-html tutorial-html CSS

Break Ape Tutorial _-html Tutorial-html image

The strain on the When method of jquery

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.