Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8885915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:25:46+00:00 2026-06-14T21:25:46+00:00

I created this question before but in another way and got no answers. So

  • 0

I created this question before but in another way and got no answers. So today I wrote some simple code to share my problem in a clear way.

  1. I used jQuery to call an image slideshow function.
  2. The AJAX function in show.php will call get.php and print the results in a DIV.

My problem is that sliding (prev – next) inside the DIV supplied by get.php does not work in show.php. But if I call get.php directly in my browser, then it works.

I am confused, I guess I have an error in my div when calling AJAX.

My Files

show.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>test </title>
        <link rel="stylesheet" type="text/css" href="demo.css" />
        <script type="text/javascript" src="jquery-1.4.2.min.js"></script>
        <script type="text/javascript" src="newscript.js"></script>
        <link href="themes/2/js-image-slider.css" rel="stylesheet" type="text/css" />
        <script src="themes/2/js-image-slider.js" type="text/javascript"></script>
        <link href="generic.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <?php
            include("samiloxide.php");
            $sql=mysql_query(" select * from  section ");

            while($r=mysql_fetch_array($sql)){
                echo "<li><a  onclick='loadpage($r[id])' >$r[section]</a></li>" ;
            }
        ?>
        <div id="pageContent"></div>
    </body>
</html>

newscript.js

var section;
function loadpage(section){ 
    var section = section.toString();

    $.ajax({
       type: "POST",
       url: "get.php",
      dataType: "script",
       data: ({section : section}),
     success: function(html){
            $("#pageContent").empty();
            $("#pageContent").append(html);
        }
    });
}

get.php

<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<style type="text/css">
    <!--
    #gallery-wrap{margin: 0 auto; overflow: hidden; width: 732px; position: relative;}
    #gallery{position: relative; left: 0; top: 0;}
    #gallery li{float: left; margin: 0 20px 15px 0;}
    #gallery li a img{border: 4px solid #40331b; height: 175px; width: 160px;}
    #gallery-controls{margin: 0 auto; width: 732px;}
    #gallery-prev{float: left;}
    #gallery-next{float: right;}
    -->
</style>

<script type="text/javascript">
    <!--
    $(document).ready(function(){ 
        // Gallery
        if(jQuery("#gallery").length){
            // Declare variables
            var totalImages = jQuery("#gallery > li").length, 
            imageWidth = jQuery("#gallery > li:first").outerWidth(true),
            totalWidth = imageWidth * totalImages,
            visibleImages = Math.round(jQuery("#gallery-wrap").width() / imageWidth),
            visibleWidth = visibleImages * imageWidth,
            stopPosition = (visibleWidth - totalWidth);

            jQuery("#gallery").width(totalWidth);

            jQuery("#gallery-prev").click(function(){
                if(jQuery("#gallery").position().left < 0 && !jQuery("#gallery").is(":animated")){
                    jQuery("#gallery").animate({left : "+=" + imageWidth + "px"});
                }
                return false;
            });

            jQuery("#gallery-next").click(function(){
                if(jQuery("#gallery").position().left > stopPosition && !jQuery("#gallery").is(":animated")){
                    jQuery("#gallery").animate({left : "-=" + imageWidth + "px"});
                }
                return false;
            });
        }
    });
    -->
</script>

           <?php
            include("samiloxide.php");
//if(!$_POST['page']) die("0");

$section = (int)$_POST['section'];

$sql=mysql_query(" select * from images  where section='$section'");

echo "
<div id='gallery-wrap'>
    <ul id='gallery'>
    ";


while($rr=mysql_fetch_array($sql)){

      echo " <li><a href='$rr[image]'><img src='$rr[image]' alt='' /></a></li>";
           }
           echo "

    </ul>
</div>
<div id='gallery-controls'>
    <a href='#' id='gallery-prev'><img src='images/prev.png' alt='' />next</a>
    <a href='#' id='gallery-next'><img src='images/next.png' alt='' />last</a>
</div>
           ";
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T21:25:47+00:00Added an answer on June 14, 2026 at 9:25 pm

    This is a bit complicated, and I am unable to provide a quick fix to your code that you could just copy, paste and verify.

    In get.php, you load a document with a gallery, and you make it a working gallery from $(document).ready().

    But in show.php, when you load the get.php file, $(document).ready() is not called. The $(document).ready() of show.php was already called long before, and your document is now in the interactive state. So when you load the layout, you do not automaticallly execute the code that makes that layout work.

    You have to move the $(document).ready() code in your get.php into show.php, and then bind it to the AJAX call completion. Or unbind the code in get.php: just call it from the end of the HTML without wrapping it in $(document).ready().

    This is not guaranteed in all browsers all the time, though, because while $(document).ready() is called properly on document being ready, in show.php what you do is you ask to load a HTML file.

    And the HTML gets loaded, and so onLoad gets fired. You can’t expect different.

    Then that HTML asks to load other assets (such as images), but the browser did not know this. It has already fired the onLoad and so you already executed the gallery setup code. If the layout requires the images’ SRC to be already loaded in order to style properly, then it will not always work. It might work the second time because the images are in the browser cache. It may work on fast connections and not on slow connections; it may work with small images, quickly loaded, and not with larger images. All these behaviours indicate that images being already loaded is necessary.

    Again, a quick and dirty fix is to fire the setup after a suitable delay (but what is suitable? You can’t know). Another possibility, if all the images are of known sizes, is to supply those sizes in HTML or CSS. After all, the layout usually requires images being loaded so that they occupy space on the page, but for that, you don’t need images to be actually displayable. They might be empty spaces (maybe styled with a background).

    A third possibility, more complicated but guaranteed to work in all browsers, is to save the image SRC’s into another kind of tag (e.g. DIVs with a class of imageloading, by default hidden), and after the load() success to analyze these tags and convert them to IMGs attaching an onload to them. When all those onloads have fired, you know that it’s OK to launch the gallery setup. While longer to describe (and code), this last method is actually much faster than the naive “quick fix: wait a bit and fire setup” one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried to ask a variant of this question before. I got some
I've just started learning ruby, so this question is simple. I created @subject in
This isn't a javascript question but I've created a fiddle so I can demonstrate
Various incarnations of this question have been asked here before, but I thought I'd
Apologies if the question isn't clear but I couldn't think of another way to
I know similar flavors of this question has been asked before, but I am
I know this question was asked before, but before marking it as a duplicate,
I posted this question here before but there were no responses. I may have
Based on this question I've created a small application which is catching all debug
To explain my question I have created this http://jsfiddle.net/Jams/XNVB2/ here I want when div1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.