2012-07-18 57 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

相关问题