tags:

views:

2353

answers:

1

I am using jQuery and AJAX. When clicking the Hyperlink, the associated document to be loaded in Popup Menu works fine. The problem comes when I use AJAX.

My Code:

//index.html
....
 jQuery.ajax({
         type:'POST',
         url:' my.php',
         data:'one='+one,

           success: function(data){

          jQuery("#another").load("load.html");

                //pop up code for the Load.html
                               jQuery("a[rel='pop']").click(function (e) {
                               e.preventDefault();
                               var features =  "height=700,width=800,scrollTo,resizable=1,scrollbars=1,location=0";
                   newwindow=window.open(this.href, 'Popup', features);
                    return false;
                     }); 

           }//success
        }); //ajax

Strategy: After Seeing the Hyperlink , The associated content will need to be displayed in popup.

//Load.html

<a href="pdf/file1.pdf" id="pop" rel="pop"> click 1.</a>
<a href="pdf/file2.pdf" rel="pop">click2</a>

Since Load.html, dynamically loads in index.html, all tag associated with pdfs link the load.html will not display the document in popup. I need help to change my code to do the above output.

A: 

I think the problem you are having is that you aren't waiting for the content of load.html to finish loading via ajax. You need to setup a callback for that call in order to use it's content correctly.

Do this:

//index.html
....
jQuery.ajax({
     type:'POST',
     url:' my.php',
     data:'one='+one,
     success: function(data){
         jQuery("#another").load("load.html", function() { 
             //pop up code for the Load.html
             jQuery("a[rel='pop']").click(function (e) {
                 e.preventDefault();
                 var features = "height=700,width=800,scrollTo,resizable=1,scrollbars=1,location=0";
                 newwindow=window.open(this.href, 'Popup', features);
                 return false;
             });//click
         }//load
     });//success
});//ajax

That should solve your problem as I understand it.

KyleFarris