2012-07-18 37 views
0

在我的PHP頁面我有一個jQuery腳本來打開一個對話窗口。該代碼是作爲如何在使用ajax響應刷新數據後綁定jQuery對話框與html元素?

<script type="text/javascript"> 
      $(document).ready(function() { 
       var $loading = $('<img src="loading.gif" alt="loading" class="loading">'); 

       $('#data-specs a').each(function() { 
        var $dialog = $('<div></div>') 
         .append($loading.clone()); 

        var $link = $(this).one('click', function() { 
         $dialog 

          .load($link.attr('href')) 
          .dialog({ 
           title: '<?php echo $_GET["indQ"];?>', 
           modal: true, 
           width: 500, 
           height: 300, 
           minHeight: 300, 
           maxHeight: 600, 
           minWidth: 500, 
           maxWidth: 800 
           }); 

          $link.click(function() { 
          $dialog.dialog('open'); 

          return false; 
         }); 

         return false; 
        }); 
       }); 

       $('#dav').val(getURLParameter('davQ')); 

       $('#pathogen').val(getURLParameter('pathogenQ')); 

       $('#topicF').val(getURLParameter('topicQ')); 

       $('#ind').val(getURLParameter('indQ')); 

       $('#subind').val(getURLParameter('subindQ')); 

       $(".selfont").change(function (event) { 
         window.location = '?davQ=' + $('#dav').val() + '&pathogenQ=' + $('#pathogen').val() + '&topicQ=' + $('#topicF').val() + '&indQ=' + encodeURIComponent($('#ind').val()) + '&subindQ=' + encodeURIComponent($('#subind').val()); 
       }); 

       function getURLParameter(name) { 
         return decodeURIComponent((RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || [, null])[1]); 
       } 

      }); 
    </script> 

的數據是在使用id =「數據規格」的表。它運作良好。最近我添加了一個帶有值的下拉框,使用ajax腳本對此表進行排序,它也可以工作。但問題出在這個Ajax調用之後,當我點擊鏈接打開對話框窗口時,它在父窗口本身打開,如果我們按下瀏覽器後退按鈕,然後點擊鏈接,它將打開對話窗口而沒有錯誤!即使在使用ajax進行排序之後,我怎樣才能使這個正確?請給我一些解決方案。如圖所示我的Ajax代碼排序如下

function ajaxFunction(){ 

    //to keep selection in countryList - GP 
    var ref = document.getElementById('countryRF'); 
    for(i=0; i<ref.options.length; i++) 
    ref.options[i].selected = true; 


    var ajaxRequest; // The variable that makes Ajax possible! 

    try{ 
     // Opera 8.0+, Firefox, Safari 
     ajaxRequest = new XMLHttpRequest(); 
    } catch (e){ 
     // Internet Explorer Browsers 
     try{ 
      ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); 
     } catch (e) { 
      try{ 
       ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); 
      } catch (e){ 
       // Something went wrong 
       alert("Your browser broke!"); 
       return false; 
      } 
     } 
    } 
    // Create a function that will receive data sent from the server 
    ajaxRequest.onreadystatechange = function(){ 
     if(ajaxRequest.readyState == 4){ 
      //document.myForm.time.value = ajaxRequest.responseText; 
      document.getElementById("result").innerHTML=ajaxRequest.responseText 

     } 
    } 

    var dav = document.getElementById('dav').value; 
    var pathogen = document.getElementById('pathogen').value; 
    var topicF = document.getElementById('topicF').value; 
    var ind = document.getElementById('ind').value; 
    var subind = document.getElementById('subind').value; 
    var selObj = document.getElementById('countryRF'); 
    var cnty = loopSelected(selObj).join('~'); // join array into a string 
    var sortby = document.getElementById('sortby').value; 

    var queryString = "?dav=" + dav + "&pathogen=" + pathogen + "&topicF=" + topicF + "&ind=" + encodeURIComponent(ind) + "&subind=" + encodeURIComponent(subind) + "&cnty=" + encodeURIComponent(cnty) + "&sortby=" + sortby; 
    ajaxRequest.open("GET", "sortbyD.php" + queryString, true); 
    ajaxRequest.send(null); 
    return false; 
} 

請幫我slve這個問題..

回答

1

雖然頁面加載是第一次對話框事件被綁定元素,阿賈克斯後,您需要再次綁定對話框事件與.bind()函數

+0

感謝您的答覆,請問我該怎麼做?我會試試這個,讓你知道結果。 – Gopipuli 2012-07-18 06:40:53

+0

是否有可能在此獲得任何線索? – Gopipuli 2012-07-18 07:03:49

+0

導致?它不起作用? – 2012-07-18 07:08:27

相關問題