简体   繁体   English

使用jQuery在div中加载PHP页面

[英]Using jQuery to load a PHP Page in a div

I have this script: 我有这个脚本:

<script type='text/javascript' src='js/jquery-1.4.4.mi.js'></script>
<script type='text/javascript'>
 $('.filterMonth').change(function(){ 
alert('ijijiji');
$.ajax({ 
url: 'ajax/filterMandays.php', 
//type: 'GET', 
success: function(data){ 
  //data is returned back 
  $('#mandayTable').html(data); 
} 
}); 

}); 
</script>

and this html: 和这个HTML:

<select name ="filterMonth">
        <?php
        $array_month = array("January","February","March","April","May","June","July","August","September","October","November","December");

        foreach($array_month as $key => $month)
        {
            $value_month = $key+1;
        echo "<option value = '$value_month'>$month</option>";
        }

        ?>
        </select>
        -
        <select name = "filterYear" onChange = "filter(filterMonth.value, filterYear.value)">
        <?php
        $curYear = date('Y');
        for($i = 1990; $i<=$curYear+10; $i++)
        {
        if($i == $curYear)
        {
        echo "<option value = '$i' selected = 'selected'>$i</option>";
        }
        else
        {
        echo "<option value = '$i'>$i</option>";
        }
        }
        ?>
        </select>
        </td>
        </tr>
        </br>
        </br>
        <tr>
        <div id="mandayTable"></div>

and this php page: 和这个PHP页面:

<?php
include("all.php");


        $q = "SELECT md.mandays_id,md.employeenum,md.month,md.year,md.required_man_days,d.firstname,d.lastname 
        FROM tbl_mandays md,tbl_employee_details d 
        WHERE md.active = '1' 
        AND md.employeenum = d.employeenum 
        AND md.month = '10';";



        $res = $db->Execute($q);

        echo "<table border = 1>";

        echo "<tr><th>Employee Number</th><th>First Name</th><th>Last Name</th><th>Month-Year</th><th>Required Man Days</th><th>Edit/Delete</th></tr>";

        while($rows = $res->FetchRow()) 
        //for($i=0;$i<5;$i++)
        {
                        //iterating through // check if employee 
                        // // if(isset($row[])) {           }
                        $mandays_id = $rows[0];

                        $empnum = $rows[1];

                        $month_year = $rows[2] ."-" .$rows[3];

                        $required_man_days = $rows[4];

                        $firstname = $rows['month'];

                        $lastname = $rows[6];




                        //echo approvers here are not taken
                        //<a href=\"view_team.php?id=".$empnum."\" -> for someone to view the people beneath them (like org tree)
                        echo "<tr><td>".$empnum  . "</td><td>".$firstname ."</td><td>".$lastname ."</td><td>" . $month_year ."</td><td>" .$required_man_days  . "</td><td width = \"200\" align = \"center\"><a href = 'edit_mandays.php?mandays_id=$mandays_id');'>Edit/Delete</a></td></tr>";
        }



        echo "</table>";


        ?>

the script should basically load the php page in the div in the html once the "filterMonth" has been changed. 一旦更改了“ filterMonth”,脚本基本上应该将html中的php页面加载到html中。 but it doesn't work. 但这不起作用。

what seems to be the problem? 似乎是什么问题? :( :(

The selector in your jQuery is $('.filterMonth') but your select box doesn't have the filterMonth class. jQuery中的选择器是$('.filterMonth')但您的选择框没有filterMonth类。 You need to change it to $('select[name=filterMonth]') . 您需要将其更改为$('select[name=filterMonth]')

In order for the jQuery selector to contain your select, you need to make sure that it runs after the Select element is in the DOM (ie: lower down the HTML), or run your JavaScript once the document has finished loading, for example: 为了使jQuery选择器包含您的选择,您需要确保它在Select元素位于DOM中之后运行(即:降低HTML),或者在文档加载完成后运行JavaScript,例如:

<script type='text/javascript' src='js/jquery-1.4.4.mi.js'></script>
<script type='text/javascript'>
  jQuery(function() {
    // do your DOM selections here, this function only runs once the document is loaded
  });
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM