javascript - how to control class on ajax response text? -


i returning data ajax call , based on , display button class visible or hidden...

but should do, when want keep visibility hidden case of reponses below

<div class="ui positive right labeled icon button" style="display:none;" id="add_wholesaler_button">   add wholesaler   <i class="checkmark icon"></i> </div> 

javascript

var code = $('#search_wholesaler').val(); if (code == "" || code.length < 1) {    add_wholesaler_button.style.display = 'none';   document.getelementbyid('namewhole').innerhtml = "";   return false; } else {   var xhttp = new xmlhttprequest();   xhttp.onreadystatechange = function() {     if (xhttp.readystate == 4 && xhttp.status == 200) {       add_wholesaler_button.style.display = 'inline';       document.getelementbyid('namewhole').innerhtml = xhttp.responsetext;     }    };   xhttp.open("get", "getwholesaler" + '/' + code, true);   xhttp.send(); } 

now should when receive response "no id exists" , wanted revert display visibilty hidden?

any appreciated

if understand correct want hide element if ajax response equal "no id exists" add code inside ajax

if (xhttp.responsetext == 'no id exists') {     add_wholesaler_button.style.display = 'none'; } 

is needed?


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -