2013-04-12 17 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>"; 
    ?> 
相关问题