Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery .load() not working

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:

  • The library loads just fine.
  • If I enter any other code, it works (like testing alert(1);).
  • The console doesn't report any errors.
  • The div stays blank; in fact, it doesn't even show. It is there, though.

What am I doing wrong?

like image 247
TW_ Avatar asked Feb 27 '13 08:02

TW_


People also ask

How to use load function in jQuery?

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).

How to load div in jQuery?

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.

How to load URL in ajax?

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.


2 Answers

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>
like image 139
rajesh kakawat Avatar answered Oct 28 '22 21:10

rajesh kakawat


.load can pass your GET params seperate:

.load("link to php", "http://examplepage.com/forum/showthread.php", "tid=NN#pid_NN")
like image 27
Rhys Lees Avatar answered Oct 28 '22 22:10

Rhys Lees