Jump to content

Inserting script into AJAX


ebolt007

Recommended Posts

I have an ajax script I had a problem with earlier, http://www.phpfreaks.com/forums/index.php?topic=354771.0 and I'm trying to insert

<script src="js/wall.js" type="text/javascript" charset="utf-8"></script> into my loadmore file. How would I do this? Right now, if I put this in my loadmore file it fires everytime the loadmore file. Basically this wall.js allows me to hide and show extra internal pieces, I have it in the header of my main file, but that doesn't pull into my loadmore.php file, and if I put this outside my postitem container, then the files thinks there is still info to load, pretty much like the problem I was having where there were spaces at the end of a few of my php files so the ajax never really finished. Here's my code again in case noone wants to goto the link. :)

 

My AJAX

<script type="text/javascript">
	$(window).scroll(function(){
	    if($(window).scrollTop() == $(document).height() - $(window).height()){
	    	$('div#loadmoreajaxloader').show();
			$.ajax({
				url: "loadmore.php?lastid=" + $(".postitem:last").attr("id"),
				success: function(html){
					if(html){
						$("#postswrapper").append(html);
						$('div#loadmoreajaxloader').hide();
					}else{
						$('div#loadmoreajaxloader').html('<center>No more posts to show.</center>');
					}
				}
			});
	    }
	});
</script>

 

my loadmore.php

if($_GET['lastid']){
               $mainID = $_GET['lastid'];
$page_query = mysql_query("
                         SELECT * FROM Users_Pokes WHERE ToID = '$user_ID' AND PokeMainID < '$mainID' OR FromID = '$user_ID' AND PokeMainID < '$mainID' order by DateSent desc LIMIT 0, 5");

                      	while ($poke_row = mysql_fetch_assoc($page_query))
                      	{
                         $poke_idmain = $poke_row['PokeMainID'];
<div class="postitem" id="<?echo $poke_idmain;?>"><?echo $poke_idmain;?></div>
}

 

my main file

    <div id="wrapper">
	                    <div id="postswrapper">
$page_query = mysql_query("
                         SELECT * FROM Users_Pokes WHERE ToID = '$user_ID' OR FromID = '$user_ID' order by DateSent desc LIMIT 0, 5");

                      	while ($poke_row = mysql_fetch_assoc($page_query))
                      	{
                          $poke_idmain = $poke_row['PokeMainID'];
<div class="postitem" id="<?echo $poke_idmain;?>"><?echo $poke_idmain;?></div>

}
</div>
	<div id="loadmoreajaxloader" style="display:none;"><center><img src="../main-site-images/ajax-loader2.gif" /></center></div>
</div>

 

Thanks

Link to comment
Share on other sites

Anyone? basically inside my wall.js I have a few functions,

 

$(document).ready(function() {

 

                var showText='Show';

my code..

});

 

and these functions don't fire when my ajax loads the info from my loadmore.php file. It works if I put the <script src="js/wall.js" type="text/javascript" charset="utf-8"></script> in the loadmore.php file, but everytime I load the loadmore.php page it loads this file again and I'll have like 5 "Shows" on my page because everytime the page loads it loads the script again, how do I get this to load once, and carry into the ajax loaded doc with the code below?

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.