1 <html> 2 3 <head> 4 <title>Parcel Sandbox</title> 5 <meta charset="UTF-8" /> 6 <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"></script> 7 </head> 8 9 <body> 10 <button id='btn'>Get Data</button> 11 12 <script> 13 function showError(e) { 14 console.warn("Error", e); 15 } 16 17 function fail() { 18 console.log("fail", arguments); 19 } 20 21 function success() { 22 console.log("success", arguments); 23 } 24 25 function getUser(id) { 26 return new Promise((a, b) => { 27 if (id % 2 == 0) { 28 a(654321); 29 } else { 30 b(123456); 31 } 32 }); 33 } 34 35 $ ( "BTN #"). ON ( "the Click", () => { 36 the getUser (666 ) 37 [ // When then the parameter is not in any way when the two perform the catch 38 is .then (Success, Fail ) 39 // .finally (Success) 40 // when then the absence of the second parameter b can not find a function will trigger an exception is captured catch 41 is . catch (ShowError); 42 is }); 43 is </ Script> 44 is </ body> 45 46 is </ HTML>