Load content from another jquery file

Asked

Viewed 1,603 times

0

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

The mistake here would be :

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

I thought the load would do the same include of php someone can 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 performing the function.

  • 1

    php is a server-side interpreted language, meaning I don’t know any way to pull the server source code via client-side code like jQuery. The fact that the button is not working properly may be because some file has not been properly loaded by the load() function. But to be able to help it would be necessary that you post files the code that loads the load and what is loaded by this load.

  • Fabio , the only thing that the load carries and this code above only that , would be as an example , to start working on , but the button does not function

  • The page that is loaded it has internal css and js? You looked if these elements were loaded?

  • Confusing question... when you ask a question, think about the person who will read and knows nothing about your system and much less what you intend! Try to put relevant information in an organized way. Do you want to load an HTML containing a button and press it nothing happens? What should the button do? What contains your HTML?

  • 1

    Ajax not working? Below is a link explaining a little more http://www.linhadecodigo.com.br/artigo/3585/ajax-basico-introducao.aspx

2 answers

3

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

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

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

});

1


What must be happening, is that you do the bind of the event on load of the page, however it is only inserted after this, thus being without any action, what you have to do, is bring along with it, the javascript which 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>
  • intendi !! then the function would have to be loaded along with the page pulled by the right load?? here I left the function on the main page and the html code on the secondary page, when I put the Submit code together with html.html like your example , it worked perfect !! thank you so much for understanding my question and for your time , I appreciate the help

  • 1

    It’s around Jonnys, I suggest you do a little research on DOM. Here is some good content to start with: http://www.w3schools.com/js/js_htmldom.asp

Browser other questions tagged

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