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

3
  • question is unclear? can you elaborate with some piece of code you have tried and facing problem? Commented Mar 3, 2017 at 18:08
  • I use this script: <script> $(document).ready(function(){ $("#artists").click(function(){ $("#content").load('link to content.php'); }); });</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 Commented Mar 3, 2017 at 18:13
  • Caro didn't get you Commented Mar 3, 2017 at 18:13

2 Answers 2

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']; ?>');
});
Sign up to request clarification or add additional context in comments.

2 Comments

i open the page 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 example.com/biography.php leads to just the content thats opened in the index.
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 example.com?url=example.com/biography.php
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.