我只是想知道我是否可以在AJAX中同时调用两个URL。你看我在同一时间使用jquery加载两个页面而且我打算使用由jQuery组成的分页。我能看到的唯一解决方案是为此创建几个页面。
这是我要加载的第一个页面。这会根据下拉框中选择的选项调用不同的php脚本。
<script type="text/javascript" src="../js/highcharts.js"></script>
<script type="text/javascript" src="../js/modules/exporting.js"></script>
<script type="text/javascript" src="../js/themes/gray.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$("#view").change(function(event)
{
var view=$(this).val();
switch(view)
{
case "daily":
{
$("#graph").load('pagination.php');
break;
}
case "weekly":
{
$("#graph").load('weekly_graph.php');
break;
}
case "monthly":
{
$("#graph").load('monthly_graph.php');
break;
}
case "yearly":
{
$("#graph").load('yearly_graph.php');
break;
}
default:
{
}
}
});
});
</script>
</head>
<body>
<div align="center">
<select id="view">
<option>(Choose which view...)</option>
<option value="daily" >Daily</option>
<option value="weekly">Weekly</option>
<option value="monthly">Monthly</option>
<option value="yearly">Yearly</option>
</select>
</div>
<br/>
<div id="graph"><?php include ('pagination.php');?></div>
示例我已选择每月视图,将包含两个页面,然后可以看到另外两个下拉菜单。从下拉菜单中选择选项时将再调用另外两页。
<script type="text/javascript">
$(document).ready(function()
{
$("#months").change(function(event)
{
var m=$(this).val();
if(m!='00' || m!='NULL')
{
$("#memcount").load('month.php', {"m":m, "y": $("#years").val()});
$("#top10").load('top10_monthly.php', {"m":m, "y": $("#years").val()});
}
});
$("#years").change(function(event)
{
var y=$(this).val();
if(y!='10' || y!='NULL')
{
$("#memcount").load('month.php', {"y":y, "m": $("#months").val()});
$("#top10").load('top10_monthly.php', {"y":y, "m": $("#months").val()});
}
});
});
</script>
<div>
<select id="months">
<option value='00'>Month...</option>
<option value='01'>Jan</option>
<option value='02'>Feb</option>
<option value='03'>Mar</option>
<option value='04'>Apr</option>
<option value='05'>May</option>
<option value='06'>June</option>
<option value='07'>July</option>
<option value='08'>Aug</option>
<option value='09'>Sept</option>
<option value='10'>Oct</option>
<option value='11'>Nov</option>
<option value='12'>Dec</option>
</select>
<select id="years">
<?php
for($yr=10; $yr<=$year; $yr++)
{
echo "<option value='".$yr."'>".$years[$yr]."</option>";
}
?>
</select>
</div>
<div id ="memcount"><?php include('curr_month.php')?></div>
<div id="top10"><?php include('curr_top10m.php')?></div>
每个要加载的页面我必须放置一个jquery分页。有人请帮我这个吗? :(
示例分页
$sql = "SELECT * FROM tbl_user WHERE admin_level LIKE 'CRD' ORDER BY id LIMIT $start, $per_page";
$result =mysql_query($sql);
date_default_timezone_set('Asia/Taipei');
$today = date('m');
$b=0;
while($row = mysql_fetch_array($result))
{
$name[$b] = $row['first_name'];
$id[$b]= $row['id'];
$b++;
}
for($i=0; $i< $b; $i++)
{
$aug_id = mysql_query("SELECT count(crdid) AS augtotal FROM crd_project
WHERE crdid!='NULL'
AND timestamp LIKE '%/$today/%'
AND crdid='$id[$i]'");
while($aug_num= mysql_fetch_array($aug_id))
{
$aug_tot[] = (int)$aug_num['augtotal'];
}
}
/* --------------------------------------------- */
$query_pag_num = "SELECT count(*) AS count FROM tbl_user WHERE admin_level LIKE 'CRD'";
$result_pag_num = mysql_query($query_pag_num);
$row = mysql_fetch_array($result_pag_num);
$count = $row['count'];
$no_of_paginations = ceil($count / $per_page);
/* ---------------Calculating the starting and endign values for the loop----------------------------------- */
if ($cur_page >= 7)
{
$start_loop = $cur_page - 3;
if ($no_of_paginations > $cur_page + 3)
{
$end_loop = $cur_page + 3;
}
else if ($cur_page <= $no_of_paginations && $cur_page > $no_of_paginations - 6)
{
$start_loop = $no_of_paginations - 6;
$end_loop = $no_of_paginations;
}
else
{
$end_loop = $no_of_paginations;
}
}
else
{
$start_loop = 1;
if ($no_of_paginations > 7)
{
$end_loop = 7;
}
else
{
$end_loop = $no_of_paginations;
}
}
$msg .= "<div class='pagination'><ul>";
// FOR ENABLING THE PREVIOUS BUTTON
if ($previous_btn && $cur_page > 1)
{
$pre = $cur_page - 1;
$msg .= "<li p='$pre' class='active'>Previous</li>";
}
else if ($previous_btn)
{
$msg .= "<li class='inactive'>Previous</li>";
}
// TO ENABLE THE NEXT BUTTON
if ($next_btn && $cur_page < $no_of_paginations)
{
$nex = $cur_page + 1;
$msg .= "<li p='$nex' class='active'>Next</li>";
}
else if ($next_btn)
{
$msg .= "<li class='inactive'>Next</li>";
}
$total_string = "<span class='total' a='$no_of_paginations'>Page <b>" . $cur_page . "</b> of <b>$no_of_paginations</b></span>";
$msg = $msg. "</ul>".$goto . $total_string . "</div>"; // Content for pagination
echo $msg;
$data = json_encode($aug_tot);
$fname = json_encode($name);
$number = json_encode($b);
}
?>
<div id='memcount' style='width: 800px; height: 400px; margin: 0 auto'></div>
<script type="text/javascript">
var chart;
$(document).ready(function() {
chart = new Highcharts.Chart({
chart: {
renderTo: 'memcount',
defaultSeriesType: 'column',
marginRight: 130,
marginBottom: 25
},
title: {
text: 'Daily Count of Added Clients',
x: -10 //center
},
xAxis: {
categories:<?php echo $fname;?>
},
yAxis: {
title: {
text: 'Number of Clients'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
legend: {
layout: 'vertical',
align: 'left',
},
series: [{
name: 'Total',
data: <?php echo $data;?>
}]
});
});
</script>
答案 0 :(得分:0)
使用ajax,您无法同时调用两个页面。
您可以在服务器端创建一个帮助页面,它将您尝试检索的两个页面组合在一起。