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 4595752
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:01:02+00:00 2026-05-21T23:01:02+00:00

I’m making a small website using ajax, mainly by curiosity. I wan’t to use

  • 0

I’m making a small website using ajax, mainly by curiosity.

I wan’t to use Fancybox to display images in an ajax content.

The thing I’m currently doing is very simple, I have a main html page, and hyperlinks just change the content of a single div… for example :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

  <head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
    <script type="text/javascript" src="jquery.fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
    <script type="text/javascript" src="js/ajax.js"></script>

    <link rel="stylesheet" href="jquery.fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.css" type="text/css" media="screen" />
  </head>

  <body>

    <div>
      <a href="javascript:void(0)" onclick="xml_doc('ajax', 'ajax.html')"> test </a>
    </div>

    <div id="ajax">
    </div>

  </body>

</html>

and the basic js code :

function xml_obj()
{
    var xmlhttp;

    // IE7+, Firefox, Chrome, Opera, Safari
    if (window.XMLHttpRequest)
    return new XMLHttpRequest();

    // IE6, IE5
    else
    return new ActiveXObject("Microsoft.XMLHTTP");
}

function xml_cfunc(div, xmlhttp)
{
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    div.innerHTML=xmlhttp.responseText;
}

function xml_doc(id, url)
{
    var xmlhttp = xml_obj();
    var div = document.getElementById(id);

    xmlhttp.onreadystatechange = function()
    {
    xml_cfunc(div, xmlhttp);
    };

    xmlhttp.open("GET", url, true);
    xmlhttp.send();
}

the content of the ajax.html would be a single href for example :

<a id="single_image" href="image.png"><img src="thumb.png" alt=""/></a>

Now i have to put the fancybox call somewhere :

$('a#single_image').fancybox();

But I just can’t find out where… If I put it in the html content it won’t be evaluated.

So when I click on the thumbnail, it will just send me to the full size image (with Uncaught TypeError: Cannot call method ‘appendChild’ of undefined, and Resource interpreted as document but transferred with MIME type image/png.).

All my research ended up on an opposite problem (call ajax content within fancybox).

Now my questions are:

  • Is this a correct way to use ajax?
  • How can I do so the ajax content can contain Fancybox links?

Thanks much,
Pierre-Luc

  • 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-05-21T23:01:02+00:00Added an answer on May 21, 2026 at 11:01 pm

    Got it working by starting fancybox directly in the ajax callback :

    function xml_cfunc(div, xmlhttp)
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        div.innerHTML=xmlhttp.responseText;
        $("a#single_image").fancybox();
        }
    }
    

    The drawback is that it will be proceed in each of ajax calls, but this certainly can be changed. The important is that the javascript has to be evaluated once the DOM is ready.

    Note that I know use JQuery.ajax, but the result is the same, for example :

    $.get(url,
      function(data) {
          $('#content_id').html(data);
          $("a#single_image").fancybox();
      });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
In my XML file chapters tag has more chapter tag.i need to display chapters

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.