tags:

views:

500

answers:

4

I have written jQuery Main.html, ajax.php. The ajax.php returns the link of images to Main.html

Now In Main.html, I have Image1, Image2, Image3, etc.

My Main.html

<html>
...
# ajax.php Call
...    
# Return Fields From Ajax.php
</html>

My ajax.php

echo "<a href='src1'><img src='src_path1' id='fid1' alt='Name1' /></a>Click To View image1\n";
echo "<a href='src2'><img src='src_path2' id='fid2' alt='Name2' /></a>Click To View image2\n";
// etc.

So, After executing ajax.php I get the Image locations in Main.html

Now, when I click the Image1 link from Main.html, that corresponding image should display in same window.

So I thought whether again to use jQuery to view Image on same page. Any ideas how to achieve this?

+1  A: 

It sounds like you might want to take a look at the JQuery lightbox plugin.

Russ Cam
A: 

You could do something like this:

Define this div in your html:

<div id="pictureframe"></div>

Now add an onclick handler on the image links to do the following:

$("#pictureframe").load(image_url);

You need to structure your code to easily retrieve the image_url.

kgiannakakis
A: 

try this:

put a hidden div in your page that has a img:

<div id="imageDivisionHolder" style="disply:none;">
    <img id="imageItemHolder" src="" alt="" />
</div>

set the class for all images that come from ajax.php and put the big image source in a attribute of it. I put it in Title attribute.

<img src='src_path1' id='fid1' alt='Name1' class='item' Title='src_path1_bigimage' />

and the JQuery code is:

$(document).ready(function(){
    $("img.item").click(function(){
     $("#imageItemHolder").attr("src",$(this).attr("title"));
     $("#imageDivisionHolder").show();
    });
});

OR you can write a function that do it and set the onclick of images to run it. This way is not recommended.

Ata
Thanks Ata , its another perspective result
venkatachalam
Ata Will You Check my Error spot I done , I have Modified the code and still i have problem any Solution?
venkatachalam
Hi venkatachalam, I read your answer again, but I can't understand that what's your problem. May you explain your answer more for me?
Ata
Yes Ata , The ajax.php has the following function 1.echo "<img src="src1" alt="name1"> 2.echo "<img src="src2" alt=name2>Yes its hidden by adding <display:none> while click the hyperlink thatcorresponding image need to display ,Instead i used to click image to show that Image as you suggest
venkatachalam
A: 

ajax.php output must return below html:

<a href="#" class="imageLink" title="fid1"><img src="src1" id="fid1" alt="Name1" style="display:none;" /><span>Click To View image1</span></a> 
<a href="#" class="imageLink" title="fid2"><img src="src2" id="fid2" alt="Name2" style="display:none;" /><span>Click To View image2</span></a> 
<a href="#" class="imageLink" title="fid3"><img src="src3" id="fid3" alt="Name3" style="display:none;" /><span>Click To View image3</span></a>

and JQuery:

$(document).ready(function(){
    $("a.imageLink").click(function(){
            $("#"+$(this).attr("title")).show();
     $(this).find("span").hide();
    });
});
Ata