0

I found the asnwer to my question in another thread: How to load PHP file into DIV by jQuery?

the only problem i have is: i cant send someone a link with a certain file loaded into the did. its always just the home url. is there any way to include that into the url?

i used the following code:

   $(document).ready(function(){
$("#artists").click(function(){
$("#content").load('urltocontent.php');
  });
 });

in my index.php i have a #content and everything works smoothly.

i plan on opening every content in php in that div. but when i open the page, of course the div is empty, because no link was clicked that opens content in the div. is there a way to generate an url that opens the content? so i could spread links

Community
  • 1
  • 1
Caro
  • 45
  • 1
  • 8
  • question is unclear? can you elaborate with some piece of code you have tried and facing problem? – Alive to die - Anant Mar 03 '17 at 18:08
  • I use this script: and i was able to sucessfully open the content php in the #content, and now i'm looking for a code thats shows that in the url as well. i'm planning on opening every content with this code in a certain div box, but when i visit the page the div is empty of course cuz i didnt click anything – Caro Mar 03 '17 at 18:13
  • Caro didn't get you – Alive to die - Anant Mar 03 '17 at 18:13

2 Answers2

0

Assuming you are calling your page like this : http://example.com?url=page_to_include.com

You can use this code :

$(document).ready(function(){
      $("#contents").load('<?php echo $_GET['url']; ?>');
});
Guillaume Sainthillier
  • 1,655
  • 1
  • 9
  • 13
  • i open the page http://example.com, then i click on one of the links, for the sake of an example lets say biography, in the menu and the content opens in the div. if i would like to send someone the link to the biography i cant, because the http://example.com/biography.php leads to just the content thats opened in the index. – Caro Mar 03 '17 at 18:27
  • You can add your own logic to fetch content via Ajax with the onclick event for your links. If you want to send a link to someone which put the content of a fragment in your content, you can send him a link like http://example.com?url=example.com/biography.php – Guillaume Sainthillier Mar 03 '17 at 18:35
0

You can use the # .. thats how its usually done in javascript. so by adding #artists behind the url.. Example:

$(function(){
  $("#button1").click(function(){
      $("#content").html("content of button 1. can load with ajax like you did");
  });

  $("#button2").click(function(){
      $("#content").html("content of button 2. can load with ajax like you did");
  });

  $(document.URL.substr(document.URL.indexOf('#')) ).click();


})

Now go to yoururl.php#button1

Mark Smit
  • 582
  • 4
  • 12