londhor2016-10-24 15:50:46
londhor, 2016-10-24 15:50:46

Ajax and PHP - why does the whole page load instead of a specific block?

I'm building a website right now and I'm having a problem.
Using Ajax, you need to pull one of the blocks with a unique id on the page from a specific (static) php page.

$('.link_to_main').click(function() { 
  $('#page_content').load("my_file.php #my_container");

As a result of executing the code in '#page_content, the entire my_file.php is loaded.
There is a similar code, but the file my_file.HTML and everything works fine.
Tell me how you can deal with this, or at least in which direction to dig?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Ivan Antonov, 2016-10-24

I usually do something like this.

  url: "my_file.php",
  success: function (response) {
    $('#page_content').html( $(response).filter('#my_container').html() );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question