Error searching page data with AJAX

Asked

Viewed 46 times

0

I’m trying to pull a content through ajax but I’m not getting, nothing appears in Received Jax.

HTML:

<a href="#portfolioModal54" class="portfolio-link" 
data-toggle="modal" id="executaAjax" value="Executa ajax">
    <img src="<?php echo "$imageM"?>" alt="project 2">
    <div class="fundo-port">
        <h1><?php echo "$tipo"?></h1>
        <h2><?php echo "$nome"?></h2>
     </div>
</a>

<div class="wrap RecebeAjax">
</div>

ajax.js:

$(document).ready(function(){      
   $('#executaAjax').click(function(){
      $.ajax({
          url: "ajax.php",
          success:(function(data){
               $('.RecebeAjax').html(data);
          }
   });      
});

ajax.php (content to be pulled)

<div id="text-proj">
   <h1 style="font-size: 35px;">Mania de Lanches</h1>
      <img class="linhaP" src="images/linha.png" style="padding-top: 15px;padding-left: 13px;    margin-bottom: 20px;"><img class="linhaPM" src="images/linha.png">
    <h1 style="margin-bottom: 20px;font-size: px;">Rede Social</h1><div id="prop3">

     <h2>Mídia virtual desenvolvida para a lanchonete Mania de Lanches divulgando promoções e datas especiais para atrair o consumo e interesse de seus clientes.
     </h2>
</div>
<div id="img-proj">
   <img src="images/port/full/markedigi/rede/mania/post.jpg">
</div>

2 answers

2

See if it helps:

$(document).ready(function(){      
   $('#executaAjax').click(function(){
      $.ajax({
          type: "GET",
          url: "ajax.php",
          async: true,
          dataType: 'json',
          success:(function(data){
               $('.RecebeAjax').html(data);
          }
   });      
});
  • didn’t pull the ajax

  • includes the whole url: http://<your-server>/ajax.php. Something else, html(data) could not be replaced by "innerhtml = date"?

  • 1

    I did it for Felipe Assunção’s answer and it worked. Thanks for helping @Andre

1


Whereas you just want to get an html helper $.load solves your problem, try using the implementation below:

$(document).ready(function(){      
   $('#executaAjax').click(function(){
      $(".RecebeAjax").load("ajax.php");
   });      
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="#portfolioModal54" class="portfolio-link" data-toggle="modal" id="executaAjax" value="Executa ajax">
  <img src="http://placehold.it/350x150" alt="project 2">
  <div class="fundo-port">
    <h1>Tipo</h1>
    <h2>Nome</h2>
  </div>
</a>

<div class="wrap RecebeAjax">
</div>

  • is not pulling the ajax

  • Now it was friend, I set here, thank you :)

Browser other questions tagged

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