Call in Ajax

1

I'm implementing a html of a system using the and I'm also making a call on ajax to open any page, but when it returns my url , it does not read the include of the page.

Example:

The html page: 'test.php'

<?php include('inc_header.php'); ?>

<section class="content">
</section>

<?php include('inc_rodape.php'); ?>

The call I made was this:

$.ajax({
    url: "teste.php",
    context: document.body,
    dataType: 'html',
    success: function(openHtml){
        $('.content').html(openHtml);
    }   
});

The page teste.php opens normal, but does not read the top. This class .content is an effect that does before opening the page teste.php , this part is working correctly, only this include header that does not work.

What would be the solution to this problem?

    
asked by anonymous 24.04.2014 / 16:53

1 answer

1

Example of using Ajax with PHP.

Code:

inc_header.php

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Carregamento de Pagina em Ajax</title>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
    $(document).ready(function(e) {
        $(".content").load("inc_meio.php");
    });
</script>
</head>
<body>
<section class="content">

inc_rodape.php

</section>
</body>
</html>

inc_meio.php

  <?php
      // pode conter programação também ...
     echo date("d/m/Y");
     echo "<br />";
   ?>
    carregando com ajax<Br />
    carregando com ajax<Br />
    carregando com ajax<Br />
    carregando com ajax<Br />
    carregando com ajax<Br />
    carregando com ajax<Br />
    carregando com ajax<Br />
    carregando com ajax<Br />
    carregando com ajax<Br />
    carregando com ajax<Br />
    carregando com ajax<Br />
    carregando com ajax<Br />
    carregando com ajax<Br />
    carregando com ajax<Br />
    carregando com ajax<Br />
    carregando com ajax<Br />
    carregando com ajax<Br />
    carregando com ajax<Br />

index.php

<?php
    include 'inc_header.php';
    include 'inc_rodape.php';

Running

In inc_header.php you have a script like this

$(document).ready(function(e) {
        $(".content").load("inc_meio.php");
});

which is responsible for loading ajax with inc_meio.php . When calling index.php , it will include inc_header.php and inc_rodape.php , getting as dynamic inc_meio.php or any other page you prefer

In this link , you have several examples with load. You also have $ .post , $.get , $ .getJSON and the parent $.ajax on jQuery

Rendered Page

Whereveranarrowwasrenderedviaajax( jQuery.load ), you should always render parts and fix some.     

24.04.2014 / 18:11