PDA

View Full Version : Invoking LightBox via AJAX after page has been loaded



barney beans
08-21-2009, 09:15 PM
How can I envoke the lightbox 2.04 pop up and load it with my AJAX reponse once the user clicks, calling my AJAX script?

This after the page has already been loaded.



<td rel="lightbox" class="sized2"
onClick="ajaxFunction('594512','2009-07-27','XYZ','1','011');"


Javascript ajaxFunction calls Websphere Servlet via AJAX



function ajaxFunction(_id, _timestamp, _srcProgId, _tableSeries, _pstAcctNum) {


if(xmlhttp) {
xmlhttp.open("POST","ajaxServlet",true);
xmlhttp.onreadystatechange = handleServerResponse;
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send("ajaxCommand=" + "ajaxDetails" + "&id=" + _id + "&timestamp=" + _timestamp +....);

}
}



To which I get back from the AJAX call some beautiful HTML (sorry no Image - boring I know..)



function handleServerResponse() {
if (xmlhttp.readyState == 4) {
if(xmlhttp.status == 200) {
document.getElementById("dog").innerHTML=xmlhttp.responseText;
.



Which I was setting in a div tag "dog". I am in need of presenting this xmlhttp.responseText as a pop up in the lightbox that has not yet been invoked and the entire page has been previously loaded.

I have everything installed, js, css and the like and I have the demo pasted into this very page and it works fine - with that demo image, but that image was there when the page loads.

How can I envoke the lightbox to pop up and be loaded with the AJAX response once the user OnClick() calls my AJAX script?

There has to be a way to do this with lightBox 2.04

I appreciate any insight and I have searched this forum, there are two similar topics but the tie in is not really illustrated. Thanks in advance

barney beans
08-21-2009, 09:20 PM
I am posting incomplete code becasue, well it is incomplete. The problem is not the code not working rather the code not coded.

I get the AJAX response back and I get the LightBox to pop up it's demo image. I just need to tie AJAX reponse to make the LightBox appear for the onClick() Sorry!