0

我正在使用 Jquery,它运行良好,直到我使用 Get 方法提交表单。

我正在尝试获取两个日期之间的信息。这是我的代码:

日期.php:

......

$date1 = $_GET['date1'];
$date2 = $_GET['date2'];
echo"<Form method='get' action=''>
<label>From: </label> <input class='date' id = 'date1' type='date' name='date1' size='9' value = '$date1'></input>
<label>To: </label> <input class='date' id = 'date2' type='date' name='date2' size='9' value = '$date2'></input> <br/> ";

echo "<input type='submit' class = 'center' value='submit' name='submit'>";
echo'</Form>';

if($date1 != '' && $date2 != '' ){
report($date1,$date2);
}
......

<script type='text/javascript' src='js/jquery.js'></script>
<script type='text/javascript' src='js/jquery-ui.js'></script>
<script type='text/javascript' src='js/ui.js'></script> //my jquery functions

......

ui.js:

$('.date').datepicker({dateFormat: 'yy-mm-dd'});

function toggleReport(table){   
$('#'+table).toggle('slow').colSpan = 3;
}

我的表单中的 GET 方法有什么问题吗?我应该改用ajax吗?如果我应该,我如何在 ajax 中使用 Get?直到现在我只使用 ajax 和 post 方法

谢谢!!!

编辑: 似乎这整件事不是我的问题,我的 php 中的某些东西是问题所在。

我真的很困惑,我更新了上面的 date.php 文件

这是报告功能:

function report($date1,$date2){

 $id = $_SESSION['id'];
 $techs = mysql_query("SELECT * FROM TECHS WHERE COMP_ID = '$id'")
 or die(); 
 $comps = mysql_query("SELECT * FROM COMPS WHERE COMP_ID = '$id'")
 or die(); 


  echo '<h1>Technicians</h1>';
  //tech Table
  echo "<table id='center'><tr><th id='hello'>Tech</th><th id='hello'>jobs</th><th    id='hello'></th></tr>";

 while($info = mysql_fetch_array( $techs ))  
{
$name = $info['Name'];
$jobs = mysql_query("SELECT * FROM JOBS WHERE COMP_ID = '$id' AND Technician = '$name' AND Date >= '$date1' AND Date <= '$date2' ORDER BY Date ASC") or die(); 
    $data = mysql_fetch_array( $jobs );

$number = mysql_num_rows($jobs);
if($number>'0'){
$name_st = remove_spaces($name);
$name_st.= '_t';
echo "<tr><td>$name</td><td>$number</td><td><img onclick='toggleReport(\"$name_st\");' src='images/report.png' border='0' alt='View report' title='View report'>
    </td></tr>";

    echo"
    <tr><td colspan='3' style='width:99%;' id='$name_st'  >
    <table >
        <th id='hello'>invoice</th><th id='hello'>Job ID</th><th id='hello'>Company</th><th id='hello'>Date</th><th id='hello'>Address</th><th id='hello'>Tech %</th><th id='hello'>Total</th><th id='hello'>Parts</th><th id='hello'>Company Parts</th><th id='hello'>Cash</th><th id='hello'>CC</th><th id='hello'>Check</th><th id='hello'>Fees</th><th id='hello'>Addt. Fees</th><th id='hello'>Company Balance</th><th id='hello'>Tech Balance</th><th id='hello'>Profit</th>

        ";
         $job = mysql_query("SELECT * FROM JOBS WHERE COMP_ID = '$id' AND Technician = '$name' ORDER BY Date ASC") or die(); 

        while($j = mysql_fetch_array( $job )){
            echo "<tr><td>".$j['invoice'].'</td>'.'<td>'.$j['jobID'].'</td>'.'<td>'.$j['Company'].'</td>'.'<td>'.$j['Date'].'</td>'.'<td>'.$j['Address'].'</td>'.'<td>'.$j['Tech_per'].'%</td>'.'<td>'.$j['Total'].'</td>'.'<td>'.$j['parts'].'</td>'.'<td>'.$j['comp_parts'].'</td>'.'<td>'.$j['cash'].'</td>'.'<td>'.$j['cc'].'</td>'.'<td>'.$j['check'].'</td>'.'<td>'.$j['fees'].'</td>'.'<td>'.$j['addt. fees <br> need to fix'].'</td>'.'<td>'.$j['comp_total'].'</td>'.'<td>'.$j['tech_total'].'</td>'.'<td>'.$j['profit'].'</td></tr>';
        }


        echo"
    </table></td></tr>";

}
  }
 echo '</table>';
 echo '<h1>Companies</h1>';
  echo "<table id='center'><tr><th id='hello'>Companies</th><th id='hello'>jobs</th><th   id='hello'></th></tr>";

   while($info = mysql_fetch_array( $comps ))  
 {
 $name = $info['name'];
 $jobs = mysql_query("SELECT * FROM JOBS WHERE COMP_ID = '$id' AND Company = '$name' Date >= '$date1' AND Date <= '$date2'  ORDER BY Date ASC") or die(); 
    $data = mysql_fetch_array( $jobs );

$number = mysql_num_rows($jobs);
if($number>'0'){
$name_st = remove_spaces($name);
$name_st.= '_d';
echo "<tr><td>$name</td><td>$number</td><td><img onclick='toggleReport(\"$name_st\");' src='images/report.png' border='0' alt='View report' title='View report'>
</td></tr>";

    echo"
    <tr><td id='$name_st' class = 'hidden' colspan='3'>
    <table >
        <th id='hello'>invoice</th><th id='hello'>Job ID</th><th id='hello'>Company</th><th id='hello'>Date</th><th id='hello'>Address</th><th id='hello'>Comp %</th><th id='hello'>Total</th><th id='hello'>Parts</th><th id='hello'>Company Parts</th><th id='hello'>Cash</th><th id='hello'>CC</th><th id='hello'>Check</th><th id='hello'>Fees</th><th id='hello'>Addt. Fees</th><th id='hello'>Company Balance</th><th id='hello'>Tech Balance</th><th id='hello'>Profit</th>

        ";
         $job = mysql_query("SELECT * FROM JOBS WHERE COMP_ID = '$id' AND Company = '$name' ORDER BY Date ASC") or die(); 

        while($j = mysql_fetch_array( $job )){
            echo "<tr><td>".$j['invoice'].'</td>'.'<td>'.$j['jobID'].'</td>'.'<td>'.$j['Company'].'</td>'.'<td>'.$j['Date'].'</td>'.'<td>'.$j['Address'].'</td>'.'<td>'.$j['Comp_per'].'%</td>'.'<td>'.$j['Total'].'</td>'.'<td>'.$j['parts'].'</td>'.'<td>'.$j['comp_parts'].'</td>'.'<td>'.$j['cash'].'</td>'.'<td>'.$j['cc'].'</td>'.'<td>'.$j['check'].'</td>'.'<td>'.$j['fees'].'</td>'.'<td>'.$j['addt. fees <br> need to fix'].'</td>'.'<td>'.$j['comp_total'].'</td>'.'<td>'.$j['tech_total'].'</td>'.'<td>'.$j['profit'].'</td></tr>';
        }


        echo"
    </table></td></tr>";

   }
 }
 echo '</table>';


}
4

1 回答 1

0

您的表单有一个空白action属性:

<Form method='get' action=''>

您需要将要提交的 URL 放在那里,例如,提交回相同的 'date.php' 页面:

<form method='get' action='date.php'>

(我假设您没有尝试从 JS 设置它,因为您在评论中说“所有”您的 JS 是初始化您的日期选择器控件的单个语句。如果不是这种情况,请更新您的问题以显示所有与表单相关的JS代码。)

编辑:对不起,我想我误解了这个问题。我以为你的意思是表格工作不正常。如果你说你的 JS 不能正常工作,那可能是因为它在页面加载之前运行。在您的 ui.js 文件中,尝试将您的 JS 包装在一个文档就绪处理程序中:

$(document).ready(function() {
    $('.date').datepicker({dateFormat: 'yy-mm-dd'});
});

话虽如此,如果您将页面提交回自身,那么 Ajax 将是一个合理的选择。

“我如何在 ajax 中使用 Get?”

看看$.get()$.ajax()doco - 显然“GET”实际上是type参数的默认值。

于 2012-05-30T02:14:57.863 回答