On my website, I'm trying to pull the content of a post in my forum (hosted on the same domain) and display it in a div on the homepage, using jQuery.
Here's the code for the header:
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
<script type="text/javascript">
jQuery("#contain").load("http://examplepage.com/forum/showthread.php?tid=NN #pid_NN");
</script>
Then, there's the div I'd like to display the post:
<div id="contain"></div>
Things to consider:
What am I doing wrong?
The jQuery load() method is a simple, but powerful AJAX method. The load() method loads data from a server and puts the returned data into the selected element. Syntax: $(selector).
To load external HTML into a <div>, wrap your code inside the load() function. To load a page in div in jQuery, use the load() method.
Trigger a load of an Ajax data source when a URL has been set using the ajax. url() method. Note ajax. url() must be used as a setter to set the URL for the load() method to be available in the returned object.
your code should be something like this
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
js code
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#contain").load("http://examplepage.com/forum/showthread.php?tid=NN #pid_NN");
});
</script>
.load
can pass your GET params seperate:
.load("link to php", "http://examplepage.com/forum/showthread.php", "tid=NN#pid_NN")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With