1

I have two pages, index.php and block1.php I wanted to load a data from block1.php to a div #details in index.php

here's my code

index.php

<div id="pop_box">
  <div class="close"><span id="close">&times;</span></div>
  <div id="block"></div>
  <div id="details"></div>
</div>

block1.php

<script>
$(document).ready(function() {
  var lnk;
  $('[href]').click(function() {
    lnk = '';
    lnk = $(this).attr('href');
    if (lnk.charAt(1) == "b") {
      var lot = lnk;
      $.ajax({
        url: "2dmap_func.php",
        method: "POST",
        dataType: "text",
        data: {
          lot: lot
        },
        success: function(data) {
          //alert(data);
          $('index.php #pop_box #details').load(data);
        }
      });
    }
  });
});
</script>

as you can see I want to load the data from block1.php to index.php's div#details and this code doesn't work.

 $('index.php #pop_box #details').load(data);
mplungjan
  • 169,008
  • 28
  • 173
  • 236
user5567987
  • 167
  • 1
  • 12
  • 2
    You cannot change another page from your current page like that. The ajax should be on the index.php page. – Phiter Dec 07 '16 at 16:06
  • You can include `block1.php` in `index.php`. – d.coder Dec 07 '16 at 16:08
  • Possible duplicate of [How do I return the response from an asynchronous call?](http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Mueyiwa Moses Ikomi Dec 07 '16 at 16:09

1 Answers1

0

In you index.php add following line:

<?php include_once 'block1.php' ?> 

In your block1.php change following line:

$('index.php #pop_box #details').load(data);

to

$('#details').html(data); // if data is valid html
Oliver
  • 893
  • 6
  • 17