Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Is there a way to do this?

page1.php --has

<div id="main">
   <div id="content">hello</div>
</div>

index.php --has

<div id="main">
</div>

Can I somehow grab the data from page1.php inside of the content div and load it into the main div in my index.php?

I have done this with the code provided at css-tricks url: http://css-tricks.com/examples/DynamicPage/

But this uses hash change events. I don't want to use the hash feature, just the load content feature, but I can't seem to isolate the code for that because I think it's built into the bbq hashchange plugin.

Is there an Ajax way of doing it?

Something like

$(selector).find('#main').load('#content');
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
141 views
Welcome To Ask or Share your Answers For Others

1 Answer

Just put a filtering selector after the URL in .load's first argument:

$(document).ready(function() {
    $("#main").load('page1.php #content');
});

That will inject the #main div in the current page with the contents of #content from page1.php.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...