Conflict with this I get in function when I click, with this from AJAX

Asked

Viewed 28 times

-1

How do I remove the variable conflict? i already tried to put in a variable the THIS from outside not to generate conflict with the ajax THIS, even so did not change anything! inserir a descrição da imagem aqui

  • Use a global variable or simply elemento.querySelector instead of this used to apply the innerHTML

  • global variable does not help; and selecting by the element is not feasible because there are several

  • If possible click on [Edit] and post the code of how you are calling the function; of the function; etc. It is easier to analyze.

  • The this that you use inside the function, will always be that of the function. What you need to do there is to save the click on another variable and use it. In other words, the reverse of what you did.

  • Consider editing your question by adding the code instead of a "print" from the editor.

  • Post code and not image

Show 1 more comment

1 answer

1


Just one example, but I believe it makes it easier to interpret.

var thisdobotao = this;

var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
   var thisdafuncao = this;

   thisdobotao.html('Carregando...')
};

Browser other questions tagged

You are not signed in. Login or sign up in order to post.