Faisal

Faisal

  • NA
  • 73
  • 1.6k

Why triggering second event "onmouseup" is getting error !

Aug 9 2019 11:01 PM
When i click on the button it is working, but when i release the button second event "onmouseup" is triggered and ajax function is getting error. Is there anything wrong in the script ?
 
  1. <button id="myP" onmousedown="mouseDown_b()" onmouseup="mouseUp_b()">Click Me</button> 
 
  1. <script>  
  2.   
  3.                 function mouseDown_b() {  
  4.                     //e.preventDefault();  
  5.                     document.getElementById("myP").style.color = "red";  
  6.   
  7.                     $.ajax({  
  8.                         type: "POST",  
  9.                         url: "Default.aspx/testMethod_a",  
  10.                         data: "{ currentState: 1 }",  
  11.                         contentType: "application/json; charset=utf-8",  
  12.                         dataType: "json",  
  13.                         //async:false,  
  14.                         success: function () {  
  15.                             console.log("success1");  
  16.                         },  
  17.                         error: function () {  
  18.                             alert("error");  
  19.                         }  
  20.                     });  
  21.   
  22.                 }  
  23.   
  24.                 function mouseUp_b() {  
  25.                     //e.preventDefault();  
  26.                     document.getElementById("myP").style.color = "green";  
  27.   
  28.                     $.ajax({  
  29.                         type: "POST",  
  30.                         url: "Default.aspx/testMethod_a",  
  31.                         data: "{ currentState: 2 }",  
  32.                         contentType: "application/json; charset=utf-8",  
  33.                         dataType: "json",  
  34.                         //async:false,  
  35.                         success: function () {  
  36.                             console.log("success2");  
  37.                         },  
  38.                         error: function () {  
  39.                             alert("2nd_error");  
  40.                         }  
  41.                     });  
  42.                 }  
  43.             </script> 

Answers (2)