JSFiddle - React, Tailwind, and code Playground

HTML

<div id="error"><span id="error_"></span></div>
<br>
<div id="count"></div>
<button id="try">Try</button>

JavaScript

emp_error = 0;
function try_thing(){
    $.ajax({
         type: "POST",
         url: "/echo/json/",
         data: "",
         dataType: 'json',
         cache: false,
         success: function(data){
             if(data.length != 0){
                 $("#error_").html("Emp id exists");    
                 $("#error").css("background-color","red");                  
                 emp_error++;
             }
             $('#count').html("count: " + emp_error);
         }
    });
}

$('#try').click(function(){try_thing()});