Upload content from another file with jquery

0

I would like to know how to load the code from another html or php file using the $(".div").load("html.html");

The error here would be:

It loads the code perfectly, but I have a button in that HTML, the button appears right but then it does not execute anything, if I put the button directly without using the .load() function, it works right, loading using load() it does not perform the functions.

I found that load would do the same function as include of php Can someone explain me?

<input class='submit' name='entrar' type='button' value='entrar'>

I also created a file html.php and inside it I put a echo with the above code, it returned perfect on the screen but also without executing the function.

    
asked by anonymous 13.11.2016 / 20:31

2 answers

1

What should be happening is that you do the bind of the event on this button on the load of the page, but it is only inserted after that, thus leaving no action whatsoever, what you have to do is bring along with it, javascript that will be executed, for example:

Home Page

$(".div").load("html.html");

html.html

<input class='submit' name='entrar' type='button' value='entrar'>
<script>
    $(function(){
        $('input[name="entrar"]').click(function(){
            $('#meu-form').submit();
        });
    });
</script>
    
14.11.2016 / 13:19
3

Use the .on () function of jQuery. It can detect elements that are loaded after page processing.

$('form').on('click', 'input[type=submit]', function(){

    alert('Opá! Bão?');

});
    
14.11.2016 / 18:39