Button returned via ajax does not work

Asked

Viewed 54 times

1

Friends, I have a question about data recovery through ajax requests. I usually use ajax for data search. The problem arose when I decided to search for elements of type button and checkbox, as I realized that they do not work when they are loaded by this means. Look down at my code:

$.get(
                "buscar-array-pessoas",
                {plano:var_plano},
                function (retorno){

                $('.caixa-dependentes2').html(retorno);             
});

It works perfectly, I send the variable "plan", and I get the return within the class "box-dependents2". The problem is that there is a button that comes along with this return. By clicking on it, I notice that nothing happens. This proceeds?

For testing purposes, I put my "search-array-people" file to return the "a":

File "search-array-people":

  <a href="#" class="teste">botao teste</div>
  <input name="campo1[]" value=""/>
  <input name="campo2[]" value=""/>

See that the return is a button with two inputs in a row.

The link is returned normally on the page that made the request. When I click on the same nothing happens.

See the jquery:

    $(".teste").on('click', function(){  
     alert('Testando botão');
     });

Thanks in advance.

  • Where’s the code where you add the Event headphone .click? you have to delegate...

  • edited my question with more information =D

  • Luis, see the answer in the duplicate link, in practice here $('.caixa-dependentes2').on('click', '.teste', function(){ should solve the problem.

  • Sergio, you solved my problem. so should I mention the return class? didn’t know it =D Thank you very much !

  • Luis in the answer that Inkei and in this other (http://answall.com/a/5199/129) can read about this in answers from me and others. If you find something useful you can vote for the answers too.

  • I will do it ! Thank you very much Sergio

  • Luis, let’s assume that after this link, there is a second button. how do I do the "rescue" of the same based on what you taught? I tried to use "$(this). next();" but it didn’t work

  • Brings HTML into question to clarify the problem.

  • I edited my question there, see if you can understand. I added two inputs to the button. I used $(this). next() to fetch the next input, but it didn’t work.

  • Luis, this is already a different question so I leave it here in the comments. You can do it like this: https://jsfiddle.net/0ueut7kp/ Regarding the question here the solution is in the links I mentioned and you can vote there to reward good answers :)

  • Good afternoon Sergio, thanks for the clarification.. I will post a new question with a last doubt =D

Show 6 more comments
No answers

Browser other questions tagged

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