-1

ajax を使用して php 動的クエリ文字列を渡す必要があり、応答はモーダル ボックスまたはポップアップ ボックスに表示されます。ここで、私が試した一連のコードを示します。ここでは動的 URL を渡し、リクエスト ページからの結果を表示します。

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>
4

1 に答える 1

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>";
    ?>
于 2013-04-12T06:37:04.013 に答える