Call in Ajax

Asked

Viewed 260 times

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 to mine url, it does not read the include page.

Example:

The html page: 'php test.'

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

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

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

The call I made was that:

$.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 top. This class .content is an effect it does before opening the page teste.php, this part is working properly, only this include header that doesn’t work.

What would be the solution to this problem?

  • Déa, it seems to me a problem of path. Can open the page teste.php directly in the browser?

  • Hi Sergio, open normally!! :(

  • Déa, there is some echo php? because if you want to load the file then it needs to "run" first to send to the ajax request

  • There’s no echo! I don’t understand what you said

  • Have you tried as the .load()? Thus: $('.content').load("teste.php"). Replacing the $.ajax() whole.

  • What’s inside that header include?

  • bfavaretto, has the top of the web system(header to be more specific)

  • I tried, Marcelo! Nothing for nothing

  • 1

    The problem is difficult to diagnose. Could you make your test available at an accessible address? Or create a Minimum, Complete and Verifiable Example which reproduces the problem?

  • In fact, The Script seems correct, it could post the Developer Tools error in the HTTP request to see the error.

Show 5 more comments

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';

Functioning

In inc_header.php you have a script like this

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

who is responsible for carrying with ajax the inc_meio.php. By calling index.php, she will include the inc_header.php and the inc_rodape.php, staying as dynamic inc_meio.php or any other page you prefer

In that link, has several examples with load. It also has the $.post, $.get, $.getJSON and the main $.ajax on the website jQuery

Rendered Page

inserir a descrição da imagem aqui

Where an arrow has been rendered via ajax (jQuery.load), you should always render parts and fix some.

  • Look at the negatives ... !!! who will be hyenas!

  • right, got it! It’s not going like this, it must be some restriction of scripts, I give a console and does not return me the error.

Browser other questions tagged

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