2013-04-12 18 views
0

我需要通過php動態查詢字符串使用ajax和響應將顯示在模式框或彈出box.here我給我嘗試過的代碼集。我想要通過動態網址並顯示請求頁面的結果。請儘快解決。如何通過ajax從php傳遞動態查詢字符串,並將結果顯示在彈出框中

foreach ($files1 as $file) 
{ 
$url='http://localhot/list1/'.$file; 
$var1=$var1.'<div class="submit2"><li><a href="/localhost/list2.php?var='.$urls.'" id="test">'."submit".'</a></li></div>'; 

} 
<script type="text/javascript"> 
$(function() 
{ 
    $("#test").click(function(e) 
    { 

     var link=$(this); 
     e.preventDefault(); 
     $.get("/localhost/list2.php?var="+link.attr('id'),function(response){ 
       $("#ajaxresponse div").fadeOut("fast", function() 
       { 


      $("#ajaxresponse div").html(response).fadeIn(); 


}); 
     });    
    }); 
}); 

</script> 
+0

您是否收到任何錯誤? –

+0

不,我沒有得到任何錯誤 –

+0

試試這個http://stackoverflow.com/questions/15862109/jquery-ajax-call-empty-querystring/15862289?noredirect=1#comment22642458_15862289 –

回答

0

試試這個。只是一個例子!

<div id="ajaxresponse"><h2>Ajax Response</h2></div> 
    <script src="jquery-1.9.1.js" type="text/javascript"></script> 
    <?php 
    $files1=array("a","b","c","d","e"); 
    foreach ($files1 as $key=>$file) 
    { 
    $url='http://localhot/list1/'.$file; 
    $var1=$url.'<div class="submit2"><li><a href="#" id="test_'.$key.'" onClick="clickAct('.$key.')">'."submit".'</a></li></div>'; 
    echo $var1; 
    } 
    ?> 
    <script type="text/javascript"> 

    function clickAct(vals) 
     { 
      $.get("list2.php?var="+vals,function(response){ 

         $("#ajaxresponse").html(response).fadeIn(); 


      });    

    } 
    </script> 

list2.php

<?php 
    extract($_REQUEST); 
    echo "<h2>Parameter was ".$var."</h2>"; 
    ?> 
相關問題